| 1. |
Solve : problem to catch errorlevel? |
|
Answer» Dear All, i'm newbie. I tried to make a batch file to backup data(files). But before it copy the files which are needed to backup, it checks first whether there is a data to backup and give information... FOR /F "tokens=1" IN ('DIR /B %src%') DO XCOPY %src% %dest% /d /y /s Thank u for your respond, Could u help me to explain ur logic of that code? Because if i were not mistaken, it won't copy,only if %src% directory is empty. But the idea of my coding is that there will always be files in %src% dirct. and xcopy /d /s /y /l gives display list whether there is a file changing or update than check with "find" to KNOW whether there is file update and than need to backup... And also i want to give message to the user...that there is no file need to backup because no file changed. Or maybe ur code has worked like my idea, just perhaps i didn't understand it well? once again thank u...The flaw in the original logic is twofold. One there is no leading space in the string you're using in the find instruction. If you fix the first ("0 "), any numeric that is a multiple of ten will produce an errorlevel not zero. Code: [SELECT]:BACKUP new or changed files :: Check whether there are files to backup echo. Checking files... set task=There were no files to backup for /f %%i in ('xcopy %src% %dest% /d /s /y /q /l') do ( if %%i==0 goto JOBDONE ) set task=Backup new or changed files echo. %task% in %src% xcopy %src% %dest% /d /y /s goto JOBDONE Quote from: Sidewinder on June 06, 2008, 05:49:46 AM The flaw in the original logic is twofold. One there is no leading space in the string you're using in the find instruction. If you fix the first ("0 "), any numeric that is a multiple of ten will produce an errorlevel not zero. Wow....u r right, now my code is working... I didn't realize that. And i tried ur coding, it's nice, worked very well, and i never thought about that logic which is very cool ...(need more practice) also this forum... i think i'll use yours... Thank u very much.... |
|