I have to create a .BAT
file that does this:
- If
C:\myprogram\sync\data.handler
exists, exit; - If
C:\myprogram\html\data.sql
does not exist, exit; - In
C:\myprogram\sync\
delete all files and folders except (test
,test3
andtest2
) - Copy
C:\myprogram\html\data.sql
toC:\myprogram\sync\
- Call other batch file with option
sync.bat myprogram.ini
.
If it was in the Bash environment it was easy for me, but I do not know how to test if a file or folder exists and if it is a file or folder.
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: Windows batch script to delete everything in a folder except one
Finally copying just means calling COPY and calling another bat file can be done like this:
You can use IF EXIST to check for a file:
If you do not need an "else", you can do something like this:
Here's a working example of searching for a file or a folder:
Here is a good example on how to do a command if a file does or does not exist:
We will take those three files and put it in a temporary place. After deleting the folder, it will restore those three files.
Use the XCOPY command:
I will explain what the
/c /d /h /e /i /y
means:I am not sure what you mean by this, but if you just want to open both of these files you just put the path of the file like
You are using a batch file. You mentioned earlier you have to create a .bat file to use this: