Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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 minthanks in advance

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

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 ds26FOR /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

![]() |
![]() |
![]() |
| Login or Register to Reply | |
| Login | Register |
| Ads by Google |