How to ID latest version of a file with changing name

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
Me_again
Automation Wizard
Posts: 1101
Joined: Fri Jan 07, 2005 5:55 pm
Location: Somewhere else on the planet

How to ID latest version of a file with changing name

Post by Me_again » Wed Sep 14, 2005 2:15 am

I have a couple of apps that regularly write datafiles with a changing filename or extension indicatiing the version, like data21234234.txt or data.23423412

At intervals (greater than the file creation interval) I need to grab the latest version of the file and archive it.

I guess I could grab the directory to a text file and play with that, but I'm hoping someone has a better suggestion.

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

Post by JRL » Wed Sep 14, 2005 4:48 am

Me_again,

Personally, I've always liked the "dir" to a file idea.

Run>cmd /c dir [drive]:\[path] /o-d /b > [drive]:\[path]\[filename]

will give you a file list with only filenames in the list and the newest file at the top of the list descending to the oldest file at the bottom of the list.

ReadLn>[drive]:\[path]\[filename],1,NewestFile

will set "NewestFile" to the name of the newest file in the directory.

If you want the path added to the listing, just add /s after the /b.

Hope this helps,
Dick

Me_again
Automation Wizard
Posts: 1101
Joined: Fri Jan 07, 2005 5:55 pm
Location: Somewhere else on the planet

Post by Me_again » Wed Sep 14, 2005 5:03 am

Wow, thanks Dick! I didn't know that /o-d date sort was possible with windows, that's great :D

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