Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

We want to rename our *.html files to *.php but (sadly enough) have not enough knowledge to do it with a dos batchfile and/or cmd prompt command.

The problem is that each file is in seperat folder and yes 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 (MSDOS) 'FOR' command but there I am stucked.

Folder structure we use is:
parent-folder/child-folder/grandchild-folder/file.html sample: games/A/game_name/file.html, games/B/game_name/file.html, games/C/game_name/file.html and so on.

The parent folder is for all files the same, the child & grandchild folders are different for most files.

After renaming these files to .php I assume following in the .htaccess will make a permanent redirect. RedirectMatch 301 (.).html$ http://oursite.com$1.php

Looking forward to suggestions/answers, thnx in advance.

share|improve this question
add comment

5 Answers

up vote 8 down vote accepted

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. If you are on XP you can download it here

share|improve this answer
    
Soandos, Chapeau !!!!!!!!!!!! Many thanx from this side, works like a charm. –  Charles Mar 21 '12 at 11:31
    
@Charles, if this solved your problem, please click the check mark, so that everyone else that sees it will know it worked. Welcome to SuperUser. –  soandos Mar 21 '12 at 11:33
add comment

In command line:

for /f "delims=*" %a in ('dir *.html /b /s') do ren "%a" *.php

Note: 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)

share|improve this answer
add comment

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

share|improve this answer
add comment

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.

http://download.cnet.com/Flexible-Renamer/3000-2248_4-28799.html

share|improve this answer
add comment

TotalCommander: Search - Send to Panel - Multi-Rename Tool

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.