Hello,
Could you please help me in scripting following scenario using batch programming:
1. There are report files generated every hour at C:\Report, example:
Report_1a.xls
Report_1b.xls
Report_0a.xls
Report_3b.xls
2. At times 0 KB report files get generated
I have following script for copying the most recently created file to C:\LatestReport
set srcDir=C:\Report
set destdir=C:\LatestReport
set latest=
pushd "%srcDir%"
for /f "tokens=*" %%a in ('dir /b /od 2^>NUL') do set latest=%%a
if "%latest%"=="" echo Could not locate files.&goto :eof
copy "%latest%" "%destDir%"
As you could see the script doesn't ignore the 0 KB files.
I would like to enhance this script to ignore 0 KB files & pick always non-zero byte file which is most recently created and move it to C:\LatestReport
Any help suggestion would be highly appreciated
Regards,
San
Batch script to Copy most recently created nonzero byte file
Moderator: DosItHelp
Re: Batch script to Copy most recently created nonzero byte
Try something like that:
Regards
aGerman
Code: Select all
for /f "tokens=*" %%a in ('dir /b /od 2^>NUL') do (
if "%%~za" neq "0" set latest=%%a
)
Regards
aGerman
Re: Batch script to Copy most recently created nonzero byte
Thanks a lot.....that was helpful!