Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Finding most recent file on NT

Status
Not open for further replies.

Guest_imported

New member
Joined
Jan 1, 1970
Messages
0
Hi,
How to find a most recent file generated in particular directory on NT.

Example: I have these files with different timestamps
File Name size Type Timestamp
1) abc1.txt 1KB txt 08/08/2001 2:32 PM
2) abc2.txt 1KB txt 08/07/2001 2:40 PM
3) abc3.txt 1KB txt 08/06/2001 2:00 PM

My result should be abc1.txt , as 1,2,3 in the file names generated randomly .
So i need to check the file abc*.txt files with the latest one. The result should give
one value ( abc1.txt ) .
Any help will be appreciated.

Thanks
Sam
 
Something along these lines should do it:

dir abc*.txt /o-d /b > c:\abc.txt
for /F "tokens=1" %%i in (c:\abc.txt) do (set abc=%%i & goto next)
:next

rem goto next would be on the same line as the for statement in a batch file.

Basically this batch file reads in all abc files with the newest one at the top. It then reads in the first line of the file and jumps out of the for loop. In place of the set command you can use any other command you need to meet your goals. Good luck.
 
Thanks a lot for your prompt reply.
It worked fine in the NT script.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top