批处理文件复制目标文件是否已存在?

时间:2009-09-16 19:12:57

标签: batch-file rename

这是片段。 %% X是源路径。我想用目标路径替换源路径,或者只删除源路径。

%_ DEST%\ %% X在此代码段中不起作用...它检查目标文件是否已存在。检查目标文件是否存在的正确方法是什么?

call :LOGMSG Copying new jpeg image files
for %%X in (%_SRC%\*.jpeg) do if not exist %_DEST%\%%X (
    xcopy %_SRC%\%%X %_DEST% /defy >>"%run_log%"
    call sd.exe add %%X >>"%run_log%"
)

1 个答案:

答案 0 :(得分:1)

在变量中使用~n来删除路径部分。此外,您在xcopy行中不需要%_SRC\%

call :LOGMSG Copying new jpeg image files
for %%X in (%_SRC%\*.jpeg) do if not exist %_DEST%\%%~nX (
    xcopy %%X %_DEST% /defy >>"%run_log%"
    call sd.exe add %%X >>"%run_log%"
)

查看for /?以获取解释和其他好处。

相关问题