我正在尝试为朋友清理一些旧数据。放置的数据是多个文件夹,如下所示。
现在,我使用了一个正则表达式^ [0-9] [0-9] [0-9] [0-9] $和一个名为Everything的搜索引擎来查找具有四位数名称的所有可能文件夹像0000我已导出到每行包含一个目录路径的文本文件,两边用双引号括起来。
我需要编写批处理脚本来执行以下操作。
我该如何做到这一点?
答案 0 :(得分:0)
@echo off
setlocal EnableDelayedExpansion
set destination=C:\put the destination folder here
set newName=10000
rem Read the text file line by line
for /F "delims=" %%a in (thefile.txt) do (
rem Check if a folder with that name already exists in the destination directory.
set "folder=%%~Na"
if exist "%destination%\!folder!" (
rem If yes, then rename the folder and copy it.
call :getNewName folder
)
rem If not, copy without renaming the folder.
md "%destination%\!folder!"
copy "%%~a" "%destination%\!folder!"
)
rem Finally, I want to sequentially rename all the folders in the destination starting with 0000.
cd /D "%destination%"
set n=9999
for /D %%a in (*) do (
set /A n+=1
if "%%a" neq "!n:~-4!" (
ren "%%a" "!n:~-4!"
)
)
goto :EOF
:getNewName folder
set /A newName-=1
set folder=%newName%
if exist "%destination%\%folder%" goto getNewName
exit /B