Announcement

Collapse
No announcement yet.

BATCH - Massive File Extension Renaming

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • BATCH - Massive File Extension Renaming

    OK, so I'm a strong DOS Command Prompt user. I've even went to the extent of creating full RPG games using Batch Files, which is what Master Jake is all about.

    Today, someone sent me a ton of files and to execute them, I needed to change all their extensions from ".txt" to ".bat" without renaming the actual filename. I hadn't done this before, surprisingly, so I went into cmd and studied up on the for loop because I knew I would be needing it.

    Needless to say, I figured it out and am here to spread the word incase you ever come across something like this.

    -----

    When Will I Need This?
    If you ever need to change file extensions for hundreds of files from say ".png" to ".jpg" and don't want to manually rename them all.

    How I Do It Then?

    First, you'll need to make sure all the files you want to extension change are in their own directory, otherwise you'll have to do some other checking which I'm not going to be showing.

    Open notepad.

    We'll start by turning echo off, cause we don't need the directories all up in our grill.

    Code:
    @echo off
    next, we create the for loop. We need to loop through every file in the current directory and rename it from whatever it currently is, to whatever it currently is ".newextension". The extension we will be using is ".bat" because In my example, I needed to change many ".txt" files to ".bat" files so I could run them.

    To do this, make a simple for loop. The main thing to keep in mind during this for loop is that the:

    %%~nD returns the filename of the file itself (without the extension) which is exactly what we need in this case.

    Code:
    @echo off
    
    for %%D in (*) do rename %%D %%~nD.bat
    pause
    We added that simple pause at the end so we can view the results in cmd when we are done. After that, just save the file as "something.bat", drag it into the directory full of files to change, and run it. Press any key after it has completed, and WAHLAH. All your file's extensions have been successfully changed without renaming the files themselves.

    Simple, and fast. Amazing! Enjoy!

  • #2
    Originally posted by Master Jake View Post
    I needed to change all their extensions from ".txt" to ".bat" without renaming the actual filename.
    Why not just use the ren command like so

    Code:
    ren *.txt *.bat
    Time's up

    Comment


    • #3
      Originally posted by bdh View Post
      Why not just use the ren command like so

      Code:
      ren *.txt *.bat
      ... I overlooked that. Why must I over complicate things, I do that all the time.

      Can you add stupidity to the OPSEC and remove this thread because of that.

      Comment


      • #4
        LOL... I searched this and there are actually people using even more complicated methods than mine to do the exact same thing. At least I'm not the only stupid one

        Comment


        • #5
          Re: BATCH - Massive File Extension Renaming

          LMAO, if you want to over complicate the matter totally you can use http://www.advancedrenamer.com/ it works like a charm for complex rename tasks
          Play Me Coach I'm Good!!!!!

          Comment

          Working...
          X