最简单的方法:
echo No|move /-Y .\file1 .\file2
您还可以使用通配符:
echo NO|move /-Y "C:\user\Downloads\*.csv" "C:\user\downloads1\"
同样在你的情况下:
for %%f in ("C:\user\Downloads\*.csv") do (
echo No|move /-Y "%%~dpfnxf" "C:\user\downloads1\"
)
编辑:
for %%f in ("C:\user\Downloads\*.csv") do (
if exist "C:\user\downloads1\%%~nxf" (
rem move "C:\user\downloads1\%%~nxf" "C:\user\downloads1\%%~nxf.bkp"
move "C:\user\downloads1\%%~nxf" "C:\user\downloads1\%%~nf-%%N.%%~xf"
)
move /Y "%%~dpfnxf" "C:\user\downloads1\"
)
还要检查:复制文件而不覆盖
再编辑一个:
setlocal enableDelayedExpansion
for %%f in ("C:\user\Downloads\*.csv") do (
set "moved="
if exist "C:\user\downloads1\%%~nxf" (
for /l %%N in (1,1,50) do (
if not defined moved if not exist "C:\user\downloads1\%%~nxf.%%N" (
move "C:\user\downloads1\%%~nxf" "C:\user\downloads1\%%~nxf.%%N"
set moved=yes
)
)
)
move /Y "%%~dpfnxf" "C:\user\downloads1\"
)
endlocal
未测试。