Rename multiple files name in CMD

被刻印的时光 ゝ 提交于 2020-01-06 05:37:19

问题


Every of my files have the same month which I would like to replace.

The problem is the month is in the middle and after a space. It looks something like this apple Oct'18.xlsx

Base on this website, https://superuser.com/questions/475874/how-does-the-windows-rename-command-interpret-wildcards

I tried to use ren ??????Oct???*.xlsx ??????Nov???*.xlsx


回答1:


There is the SPACE missing in your file pattern. You can use the following command line...:

ren "* Oct'*.xlsx" "* Nov'*.*"

..., given that the SPACE before the month name is the last one in the file names.

Hence using that command line, the following files:

and some pears Oct'18_xyz.xlsx
apples Oct'18.xlsx
bananas Oct'18.xlsx
more fruit Oct'18_xyz.xlsx
oranges Oct'18.xlsx
plus peaches Oct'18_xyz.xlsx
strawberries Oct'18 abcdef.xlsx

...become renamed to these ones:

and some pears Nov'18_xyz.xlsx
apples Nov'18.xlsx
bananas Nov'18.xlsx
more fruit Nov'18_xyz.xlsx
oranges Nov'18.xlsx
plus peaches Nov'18_xyz.xlsx
strawberries Oct'18 Nov'ef.xlsx

As you can see, the last file has been renamed wrongly, since it violates the aforementioned restriction concerning SPACEs behind the month name.




回答2:


It's quite easy using PowerShell as a tool with the -replace operator

Powershell -NoP -C "Dir '* Oct*.xlsx'|Ren -NewName {$_.Name -Replace ' Oct',' Nov'}

Sample outout lending aschipfl's template

and some pears Nov'18_xyz.xlsx
apples Nov'18.xlsx
bananas Nov'18.xlsx
more fruit Nov'18_xyz.xlsx
oranges Oct'18.xls2x
plus peaches Nov'18_xyz.xlsx
strawberries Nov'18 abc.xlsx


来源:https://stackoverflow.com/questions/53514500/rename-multiple-files-name-in-cmd

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!