Find number of lines and copy that file

September 14, 2011 at 23:06:40
Specs: Windows XP
I'm trying to use batch file to find the numbe rof lines in a file if it matches it would copy that particular file. for example, if a.txt has got zero lines it would copy a.txt to another directory.

I've got a script below but I'm not sure how can I copy that file.

Script Test 1

@echo off & setLocal EnableDELAYedeXpansion

Set destination=C:\SAP\Outbox\EmtpyFiles
Set filename= C:\SAP\Outbox\ORD_SG_201108*.ASC

for /f "tokens=1 delims=[]" %%a in ('find /v /c "" %filename%') do (echo %%a)

Script Test 2

Set destination=C:\SAP\Outbox\ZeroKB
Set filename= C:\SAP\Outbox\ORD_SG_2011*.*
set /a cnt=0

for /f %%a in ('type %filename% ^|find "" /v /c') do (echo %filename% has %%a lines)

if %CNT% equ 0 copy %filename% %destination%

I tested with the above and it copies all the files.

Please help me, i'm new to batch file. Any help or suggestion would be greatly appreciated.

See More: Find number of lines and copy that file

Report •

September 15, 2011 at 08:16:33

@echo off & setlocal
cd C:\SAP\Outbox
for %%i in (ORD_SG_2011*.*) do if %%~zi equ 0 copy "%%i" C:\SAP\Outbox\ZeroKB > nul

Report •

September 18, 2011 at 20:57:19
Hello IVO,

Thank you for your reply. The command that you had provided it would check for size of the file instead of counting the numbe rof lines am i right?

Report •

Related Solutions

Ask Question