每当我通过脚本将文件移动到其他位置时,如果文件的名称已经存在,则文件会自动覆盖。 我应该在脚本中包含哪些命令,以便在覆盖同一文件之前询问?
@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
答案 0 :(得分:1)
MOVE /-Y file1.txt file2.txt
'MOVE'现在要求每次覆盖。在命令提示符处查看move /?
。