Oldest file copy and delete

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
Nicky Briddon
Newbie
Posts: 1
Joined: Fri May 12, 2017 12:23 pm

Oldest file copy and delete

Post by Nicky Briddon » Fri May 12, 2017 12:30 pm

This may be simple to those of you that script regularly but i don't and am not very technical but what i need to do is this;

Find oldest file in a folder - all files will have year/month/date/hour/min/sec after base file name
Copy that file to a new folder removing the year/month/date/hour/min/sec after base file name
Delete file in original location

I have searched posts but cant find anything similar to copy, please help :-)

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

Re: Oldest file copy and delete

Post by Marcus Tettmar » Wed May 17, 2017 7:57 am

Hi,

You can use the GetOldestFile function to return the oldest file in a folder.

That works off the file date. But if - as I think you are saying - it is the filename that determines "oldest" and not necessarily the modified date, then I would use GetFileList and sort the array then take first or last. If you have a sensible naming convention like YYYYMMDD then sorting it would be enough. If not you'd need a loop, parsing each filename in turn, to find the one which has the oldest date in it.
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
Sign up to our newsletter for free automation tips, tricks & discounts