这是一个有关文件是否存在的好的示例:
if exist C:\myprogram\sync\data.handler echo Now Exiting && Exit
if not exist C:\myprogram\html\data.sql Exit
我们将把这三个文件放在一个临时位置。删除文件夹后,它将还原这三个文件。
xcopy "test" "C:\temp"
xcopy "test2" "C:\temp"
del C:\myprogram\sync\
xcopy "C:\temp" "test"
xcopy "C:\temp" "test2"
del "c:\temp"
使用XCOPY命令:
xcopy "C:\myprogram\html\data.sql" /c /d /h /e /i /y "C:\myprogram\sync\"
我将解释什么/c /d /h /e /i /y
意思:
/C Continues copying even if errors occur.
/D:m-d-y Copies files changed on or after the specified date.
If no date is given, copies only those files whose
source time is newer than the destination time.
/H Copies hidden and system files also.
/E Copies directories and subdirectories, including empty ones.
Same as /S /E. May be used to modify /T.
/T Creates directory structure, but does not copy files. Does not
include empty directories or subdirectories. /T /E includes
/I If destination does not exist and copying more than one file,
assumes that destination must be a directory.
/Y Suppresses prompting to confirm you want to overwrite an
existing destination file.
`To see all the commands type`xcopy /? in cmd
使用选项sync.bat myprogram.ini调用其他批处理文件。
我不确定您的意思是什么,但是如果您只想打开这两个文件,只需将文件的路径放在
Path/sync.bat
Path/myprogram.ini
如果它在Bash环境中,这对我来说很容易,但是我不知道如何测试文件或文件夹是否存在以及它是否是文件或文件夹。
您正在使用批处理文件。前面提到过,您必须创建一个.bat文件才能使用此文件:
我必须创建一个执行此操作的.BAT文件: