I have a large sum of files within directories and sub-directories with a variety of names. Currently I have a script that can do part of what I need, but the script must be in the containing directory of files I want renamed. I want to modify my script so that it can be placed in a desired root directory of files I want to rename and have it recursively rename files within all directories. Here is my current script:


(And so on...)

Some of the file names I am working with are somewhat uniform, these are text-based documents that are named as such:


While some of these names can be interpreted then changed with the script, I am also hoping to format the script in a template format so that it may be re-purposed or used for a similar situation in the future.

I know that FOR looping is most likely what needs to be implemented, but I don't know how to do this if that is the case. How can this be achieved?

  • Can you provide more detail as to the directory structure and the old file names and new file names? – Damian T. Feb 11 '18 at 13:52
  • Mr. Medelli - What determines the new file names exactly? Are you just replacing certain characters that are in the original file name with some other character or removing those or what. So for example original file name of testing_123.txt will become testing123.txt or what? What you ask should be possible but it's not clear what file names you are starting with or more importantly what the new file names will be or what you are trying to accomplish with the new file names I suppose. All file names have numbers that need stripped, remove all underbars _, etc.? Please clarify. – Pimp Juice IT Feb 12 '18 at 18:02
  • I have updated my question, and have added names of the files I am working with. – Mr. Mendelli Feb 12 '18 at 20:59
  • I just saw your update but it's still not clear what the new names will be exactly. I see you added the new list for the files that are text based so is that list the file names to find (like the original names) of the new name of the files? There will need to be two things I think here, 1. what file names do you want to change 2. what to change those file names to once those to change are determined or found. For example, if it finds XML_log1.txt then what does it do with that file then (rename to what) or otherwise what file is it changing to that name exactly? – Pimp Juice IT Feb 27 '18 at 13:20
  • It would be something like XML_lox1.txt to XML_lox2.txt. I plan on using the script for organizational purposes, so I'll be filling out file names manually. I really just need to know the proper syntax for this function, I plan to add another template script to my collection using this method if it can be done. – Mr. Mendelli Feb 28 '18 at 5:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.