Computing.Net > Forums > Windows XP > how do i get most recent file in dir list

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

how do i get most recent file in dir list

Reply to Message Icon

Name: maya_zakry
Date: November 3, 2009 at 22:53:08 Pacific
OS: Windows XP
Product: Microsoft Windows xp professional edition
Subcategory: General
Tags: batch
Comment:

Hi,
Lets say i have a list of directory in file Path.txt.
I want to loop thru each directory list to get the pathname, and get the most recent file from each directory. How do i do this in batch file?

In Path.txt
c:\test maya
\\servername\test bryan
\\nmmham-desk\test min

thanks in advance



Sponsored Link
Ads by Google

Response Number 1
Name: ace_omega
Date: November 4, 2009 at 09:11:24 Pacific
Reply:

You really should post this in the programming forum....

Try this...

@Echo off
echo y|del Files.txt
For /F "tokens=* delims= " %%A in ('type path.txt') do (
  For /F "tokens=*" %%B in ('dir "%%A\*.*" /b /a-d /od') do (
    echo %%B > Temp.tmp
    )
  type temp.tmp >> Files.txt
  )
echo y|del temp.tmp


0

Response Number 2
Name: maya_zakry
Date: November 10, 2009 at 00:40:56 Pacific
Reply:

Ok, i managed to get this work after separating it in function. dunno why, but i have 2nd requirement. I need to get 2nd most recent file, if the recent file return file less than 500kb..

Tool.txt contains below
DS15 \\PGO-desk1.ar.com\LogFile\DS\DS15\20090901 LC14 ds26

FOR /F "TOKENS=1,2,3,4 DELIMS= " %%a IN (Tools.txt) DO (
net use x: %%b
if exist x: (
call :recent %%b
)

:recent
for /f "delims=" %%m in ('dir /od /a-d /b %~1\*.txt') do set recent=%%m
if not "%recent%" =="" (
copy "c:\keke\head.txt" + "%~1\%recent%" "c:\keke\new\%recent%"
)
if "%recent%" =="" (echo "No Log available" >> c:\keke\new\bad.txt )
pause
goto :eof


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More






Use following form to reply to current message:

Login or Register to Reply
LoginRegister


Sponsored links

Ads by Google


Results for: how do i get most recent file in dir list

How do i get access to delete a dll file www.computing.net/answers/windows-xp/how-do-i-get-access-to-delete-a-dll-file/35220.html

How do I get my boot.ini file read www.computing.net/answers/windows-xp/how-do-i-get-my-bootini-file-read/80385.html

How do I get rid of Messenger 4.7?? www.computing.net/answers/windows-xp/how-do-i-get-rid-of-messenger-47/108063.html