tags:

views:

55

answers:

2

Hi, i have to create a bat file that does this:

1 - If "C:\myprogram\sync\data.handler" exists, exit;

2 - If "C:\myprogram\html\data.sql" doesn't exists, exit;

3 - In "C:\myprogram\sync\" delete all files and folders except ('test','test3' and 'test2')

4 - Copy "C:\myprogram\html\data.sql" to "C:\myprogram\sync\"

5 - Call other bat file w/ option "sync.bat myprogram.ini".

If it was in bash enviroment it was easy for me, but i don't know how to test if a file or folder exists and if it is a file or folder :/

Thanks

+4  A: 

You can use IF EXIST to check for a file:

IF EXIST filename (
REM Do one thing
) ELSE (
REM Do another thing
)

If you want to look for a drive or directory, see http://support.microsoft.com/kb/65994 for examples

Stuart Dunkeld
+1  A: 

Type IF /? to get help about if, it clearly explains how to use IF EXIST.

To delete a complete tree except some folders, see the answer of this question: http://stackoverflow.com/questions/3008567/windows-batch-script-to-delete-everything-in-a-folder-except-one/3009151

Finally copying just means calling COPY and calling another bat file can be done like this:

MYOTHERBATFILE.BAT sync.bat myprogram.ini
Patrick