繼續我問的問題這裡:
我想問如何仍然可以進行移動,但仍然可以透過更改檔案名稱來避免覆蓋。例如,使用增量編號為檔案名稱新增後綴。
或許這個問題可能有幫助,但我不確定如何與迄今為止所做的批次文件整合。
這是我到目前為止所擁有的:
@echo off
del /S *.json
for /f "tokens=*" %%f in ('dir /a:-D /s /b') do call :SUB_COPY "%%f" "I:\"
for /f "tokens=*" %%f in ('dir /a:D /s /b') do rd "%%f"
exit /B
:SUB_COPY source_item target_dir
if not "%~3"=="" (
>&2 echo ERROR: too many arguments!
)
set "SOURCE=%~f1"
if not defined SOURCE (
>&2 echo ERROR: missing argument!
exit /B 1
) else if not exist "%SOURCE%" (
>&2 echo ERROR: source not found!
exit /B 1
)
set "TARGET=%~f2"
if not defined TARGET set "TARGET=."
for /F "delims=" %%I in ('
2^> nul xcopy /L /S /E /Y /I "%SOURCE%" "%TEMP%\" ^| findstr /V /R "^[0-9]"
') do (
> con echo "%%~I"
call :SUB_DO "%%~I" "%TARGET%"
)
exit /B
:SUB_DO source_file target_dir
set "SUFFIX="
:CHECK
if exist "%~f2\%~n1%SUFFIX%%~x1" (
set /A SUFFIX-=1
) else (
2> nul md "%~f2"
> nul 2>&1 copy /B "%~f1" "%~f2\%~n1%SUFFIX%%~x1" && (
echo INFO: copied "%~nx1" as "%~n1%SUFFIX%%~x1".
) || (
>&2 echo ERROR: copying of "%~nx1" failed!
exit /B 1
)
exit /B
)
goto :CHECK
當我運行它時它仍然有缺陷,我進入某種循環並開始創建具有奇怪文件名的文件。