Computing.Net > Forums > Programming > check folder for existance of files

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

check folder for existance of files

Reply to Message Icon

Name: AJ (by William Jimenez)
Date: October 20, 2008 at 07:09:18 Pacific
OS: Windows XP
CPU/Ram: Dell
Comment:

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.



Sponsored Link
Ads by Google

Response Number 1
Name: amlife
Date: October 20, 2008 at 07:28:44 Pacific
Reply:

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 Start

you have a loop now with, not sure on how you
can get it with single line only


0

Response Number 2
Name: klint
Date: October 20, 2008 at 09:24:58 Pacific
Reply:

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


0

Response Number 3
Name: AJ (by William Jimenez)
Date: October 20, 2008 at 09:28:15 Pacific
Reply:

Awsome Klint! that did it.

THANKS!!!


0

Response Number 4
Name: amlife
Date: October 20, 2008 at 12:20:52 Pacific
Reply:

can you please explain "for" command, I just
can't understand it.


0

Response Number 5
Name: klint
Date: October 20, 2008 at 15:18:42 Pacific
Reply:

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.


0

Related Posts

See More



Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: check folder for existance of files

folder name & number of files www.computing.net/answers/programming/folder-name-number-of-files/18201.html

PHP/MySQL check if table exist www.computing.net/answers/programming/phpmysql-check-if-table-exist/10938.html

Folder Name & Number of Files www.computing.net/answers/programming/folder-name-number-of-files/18243.html