how do i get most recent file in dir list

Microsoft Windows xp professional editio...
November 3, 2009 at 22:53:08
Specs: Windows XP
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

See More: how do i get most recent file in dir list

Report •

November 4, 2009 at 09:11:24
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

Report •

November 10, 2009 at 00:40:56
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 \\\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

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 )
goto :eof

Report •

Related Solutions

Ask Question