Saved Bookmarks
| 1. |
Solve : Batch file to copy only new files - help? |
|
Answer» This is my batch file : Where is bug ? FOR %%a IN (f:\data) DO IF NOT EXIST e:\data\%%a COPY f:\data\%a% e:\data ^^^ ||| there is an error here FOR %%a IN (f:\data) DO IF NOT EXIST e:\data\%%a COPY f:\data\%a% e:\data Quote from: Salmon Trout on November 04, 2013, 01:00:38 PM FOR %%a IN (f:\data) DO IF NOT EXIST e:\data\%%a COPY f:\data\%a% e:\data No. It's correct. When i changed from %a% to %%a i get error.FOR loop variables in a batch file are 2 percent signs followed by a letter from A to Z or from a to z such as %%a %%R etc. A variable with a percent sign, then a text string and finally another percent signs like %a% or %size% or %name% is an ordinary batch variable. If you did not have a set a=something statement PREVIOUSLY, then I expect %a% is blank and thus f:\data\%a% expands to f:\data\ so INTHAT case your command becomes copy f:\data\ e:\data Probably you have files with spaces in the names? Quote from: Salmon Trout on November 04, 2013, 01:39:57 PM FOR loop variables in a batch file are 2 percent signs followed by a letter from A to Z or from a to z such as %%a %%R etc. I checked and i have no spaces in the names. Could you write correct batch file in this case please ?Try this (will also handle filenames with spaces) FOR %%a IN (f:\data\*.*) DO IF NOT EXIST "e:\data\%%~nxa" COPY "f:\data\%%~nxa" e:\data Quote from: Salmon Trout on November 04, 2013, 02:07:44 PM Try this (will also handle filenames with spaces) It's working ! Thank you |
|