Find most current file in a directory

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
NoMadBanker
Posts: 2
Joined: 25 Sep 2012 14:35

Find most current file in a directory

#1 Post by NoMadBanker » 25 Sep 2012 14:56

I need to find the most current file in a directory. File names look like file_201009_20110921_072108.txt where the first string is the year/month the data is for the second string is the date the file was generated and the third is the time the file was generated. My challenge is that we have numerous files, but the time stamps change. I am trying to find the most current file based on these 3 elements and then set this as a variable for another batch process.
I was thinking the batch might look like this::
FOR %%1 IN (f:\shared\file_*_*_*.txt) DO SET CurrentFile=%%1

Will this pull the most recent file if I have numerous files with only a date or time change? example:: file_201009_20110921_072108.txt, file_201009_20110921_142208.txt, file_201009_20110928_180108.txt,, we would need only the file_201009_20110928_180108.txt file to be set to "CurrentFile".

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: Find most current file in a directory

#2 Post by Squashman » 25 Sep 2012 17:38

Doesn't the date and time in the file name match the modified date of the file attributes?

NoMadBanker
Posts: 2
Joined: 25 Sep 2012 14:35

Re: Find most current file in a directory

#3 Post by NoMadBanker » 25 Sep 2012 17:53

The date and time (second and third strings) would change, but the first string would be variable by month. Does this help with the potential design?

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Find most current file in a directory

#4 Post by foxidrive » 25 Sep 2012 19:52

Squashman wrote:Doesn't the date and time in the file name match the modified date of the file attributes?



What is the answer to this? Are the file date and time the same as in the filename?

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: Find most current file in a directory

#5 Post by Squashman » 26 Sep 2012 07:42

NoMadBanker wrote:The date and time (second and third strings) would change, but the first string would be variable by month. Does this help with the potential design?

That does not answer my question. I am talking about the Files Attributes. (Modified Date, Created date, Last Accessed date.)
Is the modified date and time of the file the same as the Date and time in the file name?
I would assume it is considering you are changing the date in the file name.

Post Reply