0

当我通过脚本将文件移动到另一个位置时,如果文件名已经存在,文件会自动覆盖。我应该在我的脚本中包含什么命令,以便在覆盖同一个文件之前它会询问?

@echo off
setlocal
call "H:\data\datefolder"
set TargetFolder=H:\data\%DateFolder%\final reports

call :moveAndRename "H:\data\final\XYZfolder" "%TargetFolder%\Xyz.csv"
call :moveAndRename "H:\data\final\XYZfolder2" "%TargetFolder%\Xyz2.csv"


:: Done
goto :eof



:moveAndRename
set SourceFolder=%~1
set TargetFile=%~2


:: Find the newest file in the source folder
for /f "tokens=*" %%F in ('dir /b /od /a-d "%SourceFolder%"') do set "NewestFile=%%F"

:: move and rename it to the target
copy "%SourceFolder%\%NewestFile%" "%TargetFile%"

Pause

:: Done with this subroutine
goto :eof
4

1 回答 1

1
MOVE /-Y file1.txt file2.txt

'MOVE' 现在要求每次覆盖。查看move /?命令提示符。

于 2013-08-23T08:39:31.377 回答