gpt4 book ai didi

windows - 通过将文件添加到文件夹名称并将它们移动到另一个文件夹中来递归重命名文件

转载 作者:可可西里 更新时间:2023-11-01 11:33:40 25 4
gpt4 key购买 nike

我有这个:

>upperFolder
>folder 0
>file 0
>file ...
>file n
>...
>foldern
>file 0
>file ...
>file n

...我想要这个

>upperFolder
>folder 0_file 0
>folder 0_file ...
>folder 0_file n
>...
>folder n_file 0
>folder n_file ...
>folder n_file n

例如:

我有这个:

>Pictures
>Wallpapers
>Reaper
>Skull
>Night
>Avatars
>InuYasha
>Battler
>Valentino

...我想要这个

>Pictures
>Wallpapers_Reaper
>Wallpapers_Skull
>Wallpapers_Night
>Avatars_InuYasha
>Avatars_Battler
>Avatars_Valentino

我需要这个来重命名 Windows cmd 中的大量文件。手动完成这一切变得越来越困难。提前致谢。

最佳答案

如果您只需要将文件向下移动一层,则可以从命令行执行以下命令:

for /d %D in (*) do @for %F in ("%D\*") do @move "%F" "%D_%~nxF" >nul

如果要在批处理脚本中运行命令,请将所有百分比加倍。

如果你真的想以递归的方式将层次结构中的所有文件移动到父文件夹,那么下面的批处理脚本将起作用:

for /f "eol=: delims=" %%D in ('dir /b /s /ad *^|sort /r') do (
pushd "%%D"
for %%F in (*) do move "%%F" "..\%%~nxD_%%F" >nul
popd
)

这样的目录结构

>Pictures
moveFiles.bat
pic1.jpg
pic2.jpg
>Avatars
Battler.jpg
InuYasha.jpg
Valentino.jpg
>Wallpapers
pic1.jpg
pic2.jpg
>Nature
Forest.jpg
Ocean.jpg
>Sports
Baseball.jpg
Basketball.jpg
Football.jpg

变成:

>Pictures
Avatars_Battler.jpg
Avatars_InuYasha.jpg
Avatars_Valentino.jpg
moveFiles.bat
pic1.jpg
pic2.jpg
Wallpapers_Nature_Forest.jpg
Wallpapers_Nature_Ocean.jpg
Wallpapers_pic1.jpg
Wallpapers_pic2.jpg
Wallpapers_Sports_Baseball.jpg
Wallpapers_Sports_Basketball.jpg
Wallpapers_Sports_Football.jpg
>Avatars
>Wallpapers
>Nature
>Sports

关于windows - 通过将文件添加到文件夹名称并将它们移动到另一个文件夹中来递归重命名文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16971917/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com