使用脚本任务重命名文件夹中的多个 .docx 文件

我的文件夹中有 453 个文件(全部为 .docx 类型,问题是这些文件需要以正确的格式重命名


Vendor1_FinanceReport.docx

Vendor5_FinanceReport.docx

Vendor17_FinanceReport.docx

Vendor91_FinanceReport.docx

我想将其重命名为类似的名称


Vendor1_FinanceReport_Oct_2020.docx

Vendor5_FinanceReport_Oct_2020.docx

Vendor17_FinanceReport_Oct_2020.docx

Vendor91_FinanceReport_Oct_2020.docx


幕布斯6054654
浏览 54回答 2
2回答

慕慕森

为了安全起见,我将线放在Get-ChildItem括号之间,因此代码不会故意迭代已经重命名的文件。通过添加-File开关,您可以确保仅重命名文件,而不重命名文件夹。此外,通过使用-Filter代码只会影响 .docx 文件$rootFolder = 'path\to\the\folder\where\the\files\are'$append     = '_Oct_2020'  # hardcoded as per your comment(Get-ChildItem -Path $rootFolder -Filter '*.docx' -File) |  Rename-Item -NewName { '{0}{1}{2}' -f $_.BaseName, $append, $_.Extension }

四季花海

你可以在 powershell 上尝试一下:Get-ChildItem | rename-item -NewName { $_.BaseName + "_Aug_2020" + $_.Extension}或者 CMD 中的这个for %%a in (*) do ren "%%~a" "%%~na_Oct_2020%%~xa"
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python