Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hello,
In plain english what I want to do is the following.
Check in c:\folder1\ for the existance of files file1.exe file2.dll file3.pdf if they don't exist then I want to copy them from C:\sourcefolder
I can do this is line by line with IF NOT EXIST C:\FOLDER1\FILE1.exe XCOPY .....
is there a way to do this with a for loop with just one line of code?
Thank you.

you can use labels & GOTO in batch
programming:Start
IF NOT EXIST C:\FOLDER1\FILE1.exe XCOPY
IF NOT EXIST C:\FOLDER1\FILE2.pdf XCOPY
IF NOT EXIST C:\FOLDER1\picture.PING XCOPY
GOTO Startyou have a loop now with, not sure on how you
can get it with single line only

for %%f in (file1 file2 file3 file4) do if not exist c:\folder1\%%f xcopy c:\sourcefolder\%%f c:\folder1

The for command is one of the most powerful features of Windows batch language. To learn the full set of features can get a little complicated, but if you want to know, just type FOR /? at the command prompt. To start off, the following does thingss with a number of named files (assuming you have a program called do_things_with.exe):
for %%f in (file1 file2 *.txt *.bat) do (
echo Doing things with file %%f...
do_things_with %%f
)Note that the double %% sign is needed inside a batch file, but use only a single % if you are typing the above directly at the keyboard.
A more advanced example: counting, using the for /L switch:
for /l %%i in (0 10 100) do echo %%i
The above prints the numbers 0, 10, 20,...100.

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |