Delete older than 5days files

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
Identis
Junior Coder
Posts: 26
Joined: Fri Mar 27, 2015 11:26 am

Delete older than 5days files

Post by Identis » Thu Nov 24, 2016 5:56 am

Hello,

I want to delete older than 5days files, but I don't know how to write "If" for it. Please help me.

Thank You.

Code: Select all

GetFileList>C:\temp\cs\*.csv,files
Separate>files,;,file_names
Let>k=0
FileDate>C;\temp\cs\*.csv,FailoData
GetDate>date

Repeat>k
    Let>k=k+1
    if>
    DeleteFile>k
Until>k,file_names_count

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: Delete older than 5days files

Post by Marcus Tettmar » Thu Nov 24, 2016 9:16 am

Use the IfFileChanged command:

Code: Select all

GetFileList>C:\temp\cs\*.csv,files
Separate>files,;,file_names
If>file_names_count>0
  Let>k=0
  Repeat>k
      Let>k=k+1
      Let>this_file=file_names_%k%
      IfFileChanged>this_file,>5
        DeleteFile>this_file
      Endif
  Until>k,file_names_count
Endif
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

Identis
Junior Coder
Posts: 26
Joined: Fri Mar 27, 2015 11:26 am

Re: Delete older than 5days files

Post by Identis » Thu Nov 24, 2016 9:56 am

Marcus Tettmar wrote:Use the IfFileChanged command:
Thank You!! Works very well :)

Identis
Junior Coder
Posts: 26
Joined: Fri Mar 27, 2015 11:26 am

Re: Delete older than 5days files

Post by Identis » Fri Nov 25, 2016 11:14 am

Marcus Tettmar wrote:Use the IfFileChanged command:

Code: Select all

GetFileList>C:\temp\cs\*.csv,files
Separate>files,;,file_names
If>file_names_count>0
  Let>k=0
  Repeat>k
      Let>k=k+1
      Let>this_file=file_names_%k%
      IfFileChanged>this_file,>5
        DeleteFile>this_file
      Endif
  Until>k,file_names_count
Endif
Need more help.
I have 1 folder there are many subfolders and files in it, how can i go through all subfolders and check for older files and delete them?

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: Delete older than 5days files

Post by Marcus Tettmar » Fri Nov 25, 2016 12:34 pm

Make a loop which loops through all subfolders. Inside that loop put your existing code. So you have a loop within a loop.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts