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