how to get file older than 1 or 2 weeks

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
timle
Pro Scripter
Posts: 96
Joined: Tue Apr 20, 2004 5:53 am

how to get file older than 1 or 2 weeks

Post by timle » Tue Oct 28, 2008 8:00 pm

I would like the script to look for folders that were created older than 2 weeks then delete them, but I dont see any command that would do that

thank you

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

Post by Marcus Tettmar » Tue Oct 28, 2008 8:40 pm

Use GetFileList to return a list of files. Separate to split to an array. Loop through the array of files and use FileChangedSince, or FileDate to see if the file is 2 or more weeks old.

Similar:
http://www.mjtnet.com/forum/viewtopic.php?p=5835
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

User avatar
JRL
Automation Wizard
Posts: 3532
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Tue Oct 28, 2008 9:20 pm

Here's a pure Macro Scheduler sample of how this might be done. As Marcus said, you could use Filelist> and separate> to get the file names. In the sample I've simply set the name of a variable to the name of a file.

Read the commentary about date format in the post Marcus has linked. This script works on my computer but might fail for some other computer depending on how the computer is configured.
use FileChangedSince, or FileDate
What is FileChangedSince?

Code: Select all

Let>filename=C:\test.txt

GetDate>today
FileDate>filename,file_date
Midstr>file_date,1,4,yyyy
Midstr>file_date,5,2,mm
Midstr>file_date,7,2,dd
Let>file_date=%mm%/%dd%/%yyyy%
Let>kk=0
Repeat>kk
  Add>kk,1
  Sub>today,1
  If>%today%=%file_date%,DoNotDel,Continue
  Label>DoNotDel
  Let>kk=14
  Let>DeleteFlag=NO
  Label>Continue
Until>kk=14

If>deleteflag=NO,SkipDelete
  DeleteFile>filename
Label>SkipDelete

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