Windows CMD - 根据文件夹名称重命名文件

Windows CMD - Rename files based on folder name

文件结构:仪表板 > 个人文件夹 [Spencer Farris、Tyler Manson、Alexis Gibb、Ashley Edminston] > 仪表板

我知道您可以使用简单的 ren 命令重命名文件并使用 cd 进入文件夹,但我不知道如何根据文件夹名称重命名它们。所以我有上面提到的文件夹结构。我想遍历 Dashboards 文件夹中的所有文件夹,进入每个文件夹,并将 Dashboard.xlsx 文件重命名为 "Spencer Farris Dashboard.xlsx" "Tyler Manson Dashboard.xlsx" 等

对于同一文件夹中的命令行(顶级文件夹树):


cd /d "c:\folder_target\" & for /d /r %i in (*)do ren "%i\Dashboards.xlsx" "%~ni Dashboards.xlsx"

对于 bat/cmd 个文件:


@echo off 
cd /d "c:\folder_target\"
For /D /R %%i in (*)do ren "%%i\Dashboards.xlsx" "%%~ni Dashboards.xlsx"

您可以使用 For /D/R