I have up to 4 files based on this structure (note the prefixes are dates)
- 0830filename.txt
- 0907filename.txt
- 0914filename.txt
- 0921filename.txt
I want to open the the most recent one (0921filename.txt). how can i do this in a batch file?
Thanks.
I have up to 4 files based on this structure (note the prefixes are dates)
I want to open the the most recent one (0921filename.txt). how can i do this in a batch file?
Thanks.
Here you go... (hope no-one beat me to it...) (You'll need to save the file as lasttext.bat or something) This will open up / run the oldest .txt file
Probably XP only. BEHOLD The mighty power of DOS.
Although this takes the latest filename by date - NOT by filename..
If you want to get the latest filename, change /od to /on .
If you want to sort on something else, add a "sort" command to the second line.
One liner, using EXIT trick:
EDIT:
@pam: you're right, I was assuming that the files were in date order, but you can change the command to:
then you have the file list sorted by name in reverse order.
This method uses the actual file modification date, to figure out which one is the latest file:
This method, however, chooses the last file in alphabetic order (or the first one, in reverse-alphabetic order), so if the filenames are consistent - it will work:
You actually have to choose which method is better for you.
Sorry, for spamming this question, but I just really feel like posting The Real Answer. If you want your BATCH script to parse and compare the dates in filenames, then you can use something like this:
Use regular expression to parse the relevant integer out and compare them.