【问题标题】:Batch file copy does destination file already exist?批处理文件副本是否已存在目标文件?
【发布时间】:2010-11-28 22:15:41
【问题描述】:

这里是sn-p。 %%X 是源路径。我想用目标路径替换源路径或者只是删除源路径。

%_DEST%\%%X 在这个 sn-p 中不起作用...它会检查目标文件是否已经存在。检查目标文件是否存在的正确方法是什么?

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%"
)

【问题讨论】:

  • 你的标题有错字。请将“Bath”改为“Batch”

标签: batch-file rename


【解决方案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 /? 以获得解释和其他好处。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-04-27
    • 2015-07-09
    • 2011-03-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多