简体   繁体   中英

Rename multiple files in a folder and its subfolders to a fixed pattern

I have a large number of files to be renamed to a fixed pattern on my Windows 8 computer. I am looking for a way so that I can rename the files in a quick way, any way: like any software that does it or any command on command window.

Following is what I need to do:

Original file name: Body Begger Power.docx.htm Need this to be: body-begger-power.html

From the root directory you can try this:

Get-ChildItem -Force -Recurse | Move-Item -Destination {$_.FullName.ToLower() -replace ' ', '-'}

I don't see any pattern for removing the extension. If all files are docx.html and you want them changed to html, you could simply do another replace like this:

Get-ChildItem -Force -Recurse | Move-Item -Destination {($_.FullName.ToLower() -replace ' ', '-') -replace '.docx.htm$', '.html'}

for /r %i in (.) do if exist "%i\body begger power.docx.htm" ECHO ren "%i\body begger power.docx.htm" body-begger-power.html

from the prompt will scan the tree from . (the current directory - or substitute the directoryname from which you want to start). This will simply ECHO the filenames detected to the screen - you need to remove the ECHO keyword to actually rename the file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM