How to rename multiple files in multiple folders with one command












11















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.html

  • games/B/game_name/file.html


  • games/C/game_name/file.html and 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$ http://oursite.com$1.php









share|improve this question





























    11















    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.html

    • games/B/game_name/file.html


    • games/C/game_name/file.html and 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$ http://oursite.com$1.php









    share|improve this question



























      11












      11








      11


      3






      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.html

      • games/B/game_name/file.html


      • games/C/game_name/file.html and 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$ http://oursite.com$1.php









      share|improve this question
















      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.html

      • games/B/game_name/file.html


      • games/C/game_name/file.html and 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$ http://oursite.com$1.php






      windows php html powershell batch-rename






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jan 31 '16 at 1:35









      G-Man

      5,627112358




      5,627112358










      asked Mar 21 '12 at 11:00









      CharlesCharles

      2081310




      2081310






















          5 Answers
          5






          active

          oldest

          votes


















          14














          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.






          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



















          2














          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


























          • Why do you say "delims=*"?  "delims=" should be good enough (i.e., why do you specify a delimiter of *?

            – G-Man
            Jan 31 '16 at 1:34



















          1














          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
























          • This made my day ! Thanks so much !

            – Shaig Khaligli
            Dec 8 '18 at 12:32



















          1














          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































            0














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






            share|improve this answer

























              Your Answer








              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "3"
              };
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function() {
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled) {
              StackExchange.using("snippets", function() {
              createEditor();
              });
              }
              else {
              createEditor();
              }
              });

              function createEditor() {
              StackExchange.prepareEditor({
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader: {
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              },
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              });


              }
              });














              draft saved

              draft discarded


















              StackExchange.ready(
              function () {
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f403183%2fhow-to-rename-multiple-files-in-multiple-folders-with-one-command%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              5 Answers
              5






              active

              oldest

              votes








              5 Answers
              5






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              14














              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.






              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
















              14














              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.






              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














              14












              14








              14







              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.






              share|improve this answer















              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.







              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited Jan 31 '16 at 1:36









              G-Man

              5,627112358




              5,627112358










              answered Mar 21 '12 at 11:12









              soandossoandos

              20.2k2892130




              20.2k2892130













              • 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



















              • 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

















              Soandos, Chapeau !!!!!!!!!!!! Many thanx from this side, works like a charm.

              – Charles
              Mar 21 '12 at 11:31





              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





              @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













              2














              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


























              • Why do you say "delims=*"?  "delims=" should be good enough (i.e., why do you specify a delimiter of *?

                – G-Man
                Jan 31 '16 at 1:34
















              2














              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


























              • Why do you say "delims=*"?  "delims=" should be good enough (i.e., why do you specify a delimiter of *?

                – G-Man
                Jan 31 '16 at 1:34














              2












              2








              2







              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















              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














              share|improve this answer



              share|improve this answer








              edited Mar 22 '12 at 11:40









              slhck

              161k47447470




              161k47447470










              answered Mar 21 '12 at 11:20









              ZEDA-NLZEDA-NL

              393210




              393210













              • Why do you say "delims=*"?  "delims=" should be good enough (i.e., why do you specify a delimiter of *?

                – G-Man
                Jan 31 '16 at 1:34



















              • Why do you say "delims=*"?  "delims=" should be good enough (i.e., why do you specify a delimiter of *?

                – G-Man
                Jan 31 '16 at 1:34

















              Why do you say "delims=*"?  "delims=" should be good enough (i.e., why do you specify a delimiter of *?

              – G-Man
              Jan 31 '16 at 1:34





              Why do you say "delims=*"?  "delims=" should be good enough (i.e., why do you specify a delimiter of *?

              – G-Man
              Jan 31 '16 at 1:34











              1














              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
























              • This made my day ! Thanks so much !

                – Shaig Khaligli
                Dec 8 '18 at 12:32
















              1














              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
























              • This made my day ! Thanks so much !

                – Shaig Khaligli
                Dec 8 '18 at 12:32














              1












              1








              1







              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













              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












              share|improve this answer



              share|improve this answer










              answered Mar 21 '12 at 13:33









              AaronAaron

              266




              266













              • This made my day ! Thanks so much !

                – Shaig Khaligli
                Dec 8 '18 at 12:32



















              • This made my day ! Thanks so much !

                – Shaig Khaligli
                Dec 8 '18 at 12:32

















              This made my day ! Thanks so much !

              – Shaig Khaligli
              Dec 8 '18 at 12:32





              This made my day ! Thanks so much !

              – Shaig Khaligli
              Dec 8 '18 at 12:32











              1














              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




























                1














                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


























                  1












                  1








                  1







                  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













                  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












                  share|improve this answer



                  share|improve this answer










                  answered Jun 19 '12 at 16:38









                  SriniSrini

                  111




                  111























                      0














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






                      share|improve this answer






























                        0














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






                        share|improve this answer




























                          0












                          0








                          0







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






                          share|improve this answer















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







                          share|improve this answer














                          share|improve this answer



                          share|improve this answer








                          edited Mar 28 '12 at 17:22









                          Raystafarian

                          19.5k105089




                          19.5k105089










                          answered Mar 21 '12 at 17:40









                          Lazy BadgerLazy Badger

                          3,471912




                          3,471912






























                              draft saved

                              draft discarded




















































                              Thanks for contributing an answer to Super User!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid



                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.


                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function () {
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f403183%2fhow-to-rename-multiple-files-in-multiple-folders-with-one-command%23new-answer', 'question_page');
                              }
                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              Plaza Victoria

                              Puebla de Zaragoza

                              Musa