1.

Solve : File Size Handling in Dos?

Answer»

Need Dos Batch script code for handling file size. Need way to obtain file size compare it and then goto copy mode 2 different directories.Why is it that poster's refuse to disclose their OS? Is it some kind of state secret?

Code: [Select]
for /f "tokens=1-4" %%a in ('dir /-c ^| find /i "filename.ext"') do (
if %%d GEQ nnnn (copy A B) else (copy A C)
)


nnnn = file size
filename.ext = file you're checking
A = source file
B = target file
C = different target

Good luck. Windows 2000 v.5.25 OS
Have the following code
that does return the file size but it is not EVALUATING to continue on to the copyNIS part

it is only supposed to continue if value is not null
want process to stop and not copy if file size is zero
===================================
SET HZmw_DATA=F:\INETPUB\FTPROOT\FTPmw\
SET HZmw_SCRIPTS=e:\SOFTWARE\PEPSI\MW\SCRIPTS\
SET HZmw_LOG=F:\DATA\PEPSI\mw\LOGS\
SET HZmw_BACKUP=F:\DATA\PEPSI\MW\BACKUP\


Echo Copy %HZmw_Log%HZmw.LOG to %HZmw_BACKUP%HZmw.log >> %HZmw_Log%HZmw.LOG
Echo. >> %HZmw_Log%HZmw.LOG
Copy %HZmw_Log%HZmw.LOG %HZmw_BACKUP%HZmw.log
Echo Copy %HZmw_Log%mwcalc.LOG to %HZmw_BACKUP%mwcalc.log >> %HZmw_Log%HZmw.LOG
Echo. >> %HZmw_Log%HZmw.LOG

Copy %HZmw_Log%mwcalc.LOG %HZmw_BACKUP%mwcalc.log

IF EXIST %HZmw_Log%HZmwBAT.ERR GOTO Failure

:CKNIS

ECHO Performing CkNIS in Horizon MW >> %HZmw_Log%HZmw.LOG

ECHO Checking for NISHMWP file and size >> %HZmw_Log%HZmw.LOG

SET local=size
call :getsize "F:\inetpub\ftproot\ftpmw\nishmwp.txt"

goto :EOF

:getsize
Setlocal
set /size=%~z1
echo %/size% >testNIS.txt


if (%size% == NULL) echo an error has occurred with the filesize %HZmw_DATA%NISHMWP.TXT to %HZmw_BACKUP%NISHMWP.TXT >> %HZmw_log%HZmw.LOG
rem mem /d | find "nishmwp.txt" == NULL
if errorlevel 1 GOTO CopyNIS

rem mem /d | find "nishmwp.txt" > null
rem if errorlevel 1 GOTO CopyNIS

ECHO Exiting out of cknis >> %HZmw_log%HZmw.LOG
ECHO. >> %HZmw_log%HZmw.LOG


===============================================================

:CopyNIS
Echo ATTEMPTING to Copy %HZmw_DATA%NISHMWP.TXT to %HZmw_BACKUP%NISHMWP.TXT >> %HZmw_log%HZmw.LOG
Copy %HZmw_DATA%NISHMWP.TXT %HZmw_BACKUP%NISHMWP.TXT
If Errorlevel 1 echo an error has occurred in copying %HZmw_DATA%NISHMWP.TXT to %HZmw_BACKUP%NISHMWP.TXT >> %HZmw_log%HZmw.LOG
ECHO successful copy >> %HZmw_log%HZmw.LOG
ECHO. >> %HZmw_log%HZmw.LOG

:EOF




=================
Quote

Why is it that poster's refuse to disclose their OS? Is it some kind of state secret?

Code: [Select]for /f "tokens=1-4" %%a in ('dir /-c ^| find /i "filename.ext"') do (
if %%d GEQ nnnn (copy A B) else (copy A C)
)

nnnn = file size
filename.ext = file you're checking
A = source file
B = target file
C = different target

Good luck.

NULL is not a CMD processor keyword. CMD will SEE NULL as a literal and %~z1 will presumbably resolve to a numeric value. The chance of a equal compare are pretty slim.

You MAY want to add a not exist test for %1 in the getsize routine to error out; otherwise any subsequent compare with %/size% will fail.

Note: One line SETS the /size variable, but another checks the size variable. They are not one and the same.


Hope this helps.


Discussion

No Comment Found