继续我的问题这里:
我想问一下如何才能继续移动,但又能通过更改文件名来避免覆盖。例如,在文件名后添加一个带有增量数字的后缀。
或许这个问题可能会有帮助,但我不确定如何与我迄今为止所做的批处理文件集成。
这是我目前所拥有的:
@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
它仍然存在缺陷,当我运行它时,我陷入某种循环并开始创建具有奇怪文件名的文件。