We want to rename our *.html files to *.php but (sadly enough) have not enough knowledge to do it with a cmd prompt command and/or batch file.
The problem is that each file is in separate folder –
and I am talking about 750+ different folder names.
Using wildcards for the files I know is the *but using also a wildcard for folders is unknown to me.
We probably need to use the FOR command (in Command Prompt),
but there I am stuck.
Folder structure we use is:
parent-folder/child-folder/grandchild-folder/file.html
for example:
games/A/game_name/file.htmlgames/B/game_name/file.htmlgames/C/game_name/file.htmland so on.
The parent folder is the same for all files; the child & grandchild folders are different for most files.
After renaming these files to *.php I assume the following in the .htaccess will make a permanent redirect.
RedirectMatch 301 (.*)\.html$ 5 Answers
get-childItem -recurse | Where {$_.extension -eq ".html"} | rename-item -newname { $_.name -replace ".html",".php" }
This will work in PowerShell. If you have Windows 7 or Vista, you should have it installed by default. If you are on XP you can download it here.
2In command line:
for /f "delims=*" %a in ('dir *.html /b /s') do ren "%a" *.phpNote: You can replace *.html for other wildcard, e.g. d:\www\*.html.
Note 2: If using the command within a batch file, replace %a with %%a (don't ask me why)
Using forfiles, we can write a script, to rename files recursively in all subfolders.
forfiles /S /M *.html /C "cmd /c rename @file @fname.php" Source: Batch script for renaming files in bulk
Flexible Renamer is an excellent little program that will handle several different types of renaming searches/replaces. It accepts regular expressions, and has common patterns predefined. Additionally, it allows you to include items in subfolders, or operate on folders themselves. It also gives you a preview of all changes that will be made. I have used it for years, and highly recommend it.
0TotalCommander: Search - Send to Panel - Multi-Rename Tool