cure-real
Results 1 to 5 of 5

Thread: BATCH - Massive File Extension Renaming

  1. #1
    Join Date
    Sep 2008
    Location
    United States
    Posts
    518

    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. #2
    Join Date
    Jul 2002
    Location
    JNB, ZA
    Posts
    1,781
    Quote 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

  3. #3
    Join Date
    Sep 2008
    Location
    United States
    Posts
    518
    Quote 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.

  4. #4
    Join Date
    Sep 2008
    Location
    United States
    Posts
    518
    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

  5. #5
    Join Date
    Jul 2002
    Location
    Johannesburg, Gauteng, South Africa
    Posts
    64

    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!!!!!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Just Got Done Destroying My First Batch of Cookies
    By Nothing in forum Christian Fellowship
    Replies: 26
    Last Post: Feb 22nd 2011, 03:03 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •