Batch file 重命名父文件夹子文件夹中的子文件夹
我有以下文件夹树:Batch file 重命名父文件夹子文件夹中的子文件夹,batch-file,cmd,Batch File,Cmd,我有以下文件夹树: Parent Folder > Folder_Name_Day-Month-Year > Folder Name Foo (x4) > Folder_Name_Day2-Month2-Year2 > Folder Name Foo (x4) > Folder_Name_Day3-Month3-Year3 > Folder Name Foo (x4)
Parent Folder > Folder_Name_Day-Month-Year > Folder Name Foo (x4)
> Folder_Name_Day2-Month2-Year2 > Folder Name Foo (x4)
> Folder_Name_Day3-Month3-Year3 > Folder Name Foo (x4)
> Folder_Name_Day4-Month4-Year4 > Folder Name Foo (x4)
我想将“文件夹名Foo”重命名为“文件夹名Foo Day Month Year”
我的尝试:
SETLOCAL ENABLEDELAYEDEXPANSION
pushd "C:\Users\%Username%\Desktop\ParentFolder"
for /f "tokens=*" %%K in ('dir /b /d *') do (
pushd %%K
set V=%%K
set W=!V:~18,27!
for /f "tokens=*" %%S in ('dir /b /d *') do (
rename "%%S" "%%S !W!"
)
)
问题是,它只经过第一个文件夹\u Name\u Day-Month-Year
并将其中的子文件夹重命名为文件夹名称Foo Day Month Year Day2-Month2-Year2 Day3-Month3-Year3 Day4-Month4-Year4
欢迎任何提示 你的问题不清楚。有多个细节令人困惑。但是,我假设您对第一个文件夹中正确重命名的子文件夹的描述是正确的。这样,我看到的唯一错误是缺少
popd
命令(即前面的pushd
)对:
SETLOCAL ENABLEDELAYEDEXPANSION
pushd“C:\Users\%Username%\Desktop\ParentFolder”
对于('dir/b/d*)中的/f“tokens=*”%%K,请执行以下操作(
pushd%%K
设置V=%%K
集合W=!V:~18,27!
对于('dir/b/d*)中的/f“tokens=*”%%S,请执行以下操作(
重命名“%%S”“%%S!W!”
)
popd你的字面意思是日-月-年
吗?如果不是,应该应用哪个日期?应该只是从父文件夹复制吗?如果这个答案对你有帮助,请选中它的复选标记。另外,当你有足够的代表点数时,请向上投票。这是在这个网站上说“谢谢”的方式。。。
SETLOCAL ENABLEDELAYEDEXPANSION
pushd "C:\Users\%Username%\Desktop\ParentFolder"
for /f "tokens=*" %%K in ('dir /b /d *') do (
pushd %%K
set V=%%K
set W=!V:~18,27!
for /f "tokens=*" %%S in ('dir /b /d *') do (
rename "%%S" "%%S !W!"
)
popd <- This command is missing!
)