• ARTICLES
SEARCH

How-To Geek

Stupid Geek Tricks: Randomly Rename Every File in a Directory

image

UPDATE: An “undo” function has been added to the script. There are comments in the batch script which explain how to use this.

Looking to have a little fun with your files or play a clever prank on someone? With a simple batch script you can randomly rename every file in a directory instantly.

Just copy our RandomNames.bat script into a folder and run it.

Before:

image

After:

image

Uses

While it may not be immediately obvious, there are several somewhat practical uses for this:

  • Easily bulk rename picture files to randomize the order they appear in slideshows or on digital picture frames.
  • A practical joke (see the warning below).
  • In case the “random” button on your MP3 player isn’t geeky enough for you.

Options

There are a couple of options you can configure in the script:

  • Prepend the file names – instead of renaming the entire file, a random string is added to the beginning of each file name.
  • Undo renaming -

You can set these options by opening the RandomNames.bat file in Notepad and editing accordingly. There are comments included to let you know how to set each option.

Warning!

When the script runs, it warns you that deleting the created translation file (__Translation.txt) will prevent you from being able to undo the renaming.

image

Needless to say, it would be a good idea to backup your original files before renaming them all.

Use responsibly and have fun!

 

Download RandomNames script from How-To Geek

Jason Faulkner is a developer and IT professional who never has a hot cup of coffee far away. Interact with him on Google+

  • Published 04/1/11

Comments (19)

  1. LolWaitWut

    Here, this is how you can screw someone over royally on day designated for infantile pranksterism. “Use responsibly and have fun!” – really Hw2Gk?

  2. FightTheRight

    Another totally stupid post.

  3. Ja5087

    What about a directory with about a thousand files?

  4. two replies

    @fighttheright
    And another quality comment that was totally worth posting. O_o

  5. AndreiD.

    Stupid Prankenstein !

  6. Ultra-funny

    What about executing a “format C:” ?
    That would be the ultimate super-funny prank!
    Loads of fun and tons of laughting for sure!

  7. Louis Payton

    Why on earth would you post something that is potentially so harmful when used by a prank? Do you not think some idiot will actually do this to some unsuspecting friend? I am one of your fans and look forward each day to your posts but I really think this post to be a mistake.

  8. TatoSgr

    I consider this not only as a prank, but also a way to “encrypt” your files.

  9. Jason Faulkner

    If you are the type of person who would intentionally damage someone’s data, this is nothing.

    How does it differ from other articles on this site which show, for example, how to reset OS level passwords or exact data behind a password protected OS partition?

  10. Aspartam

    will it rename everything in C:\windows\system directory, if I run it there? would be nice. :D

  11. St1400

    How do you reverse this process?

  12. MOHAN.S

    Thanks Dear,

    I learn some different batch coding from your code.

    Have a nice day.

  13. TheByzantine

    Those who cause trouble simply because they can are disgusting at best. Those who show them how are worse.

    I have no respect for this site.

  14. DarkSprout

    I have rewritten the script so that it can be run from any directory or a directory is passed to the script, also fixed the bug where the Translation text file also got randomised.
    And have also put in verbose name change listing when MakeTranslationFile is enabled.

    Altered Script

    @ECHO OFF
    ECHO Random Names
    ECHO Written By: Jason Faulkner
    ECHO Rewritten By: DarkSprout [Apr11]
    ECHO HowToGeek.com
    ECHO.
    ECHO.

    :: Randomly renames every file in a directory.

    SETLOCAL EnableExtensions EnableDelayedExpansion

    :: Set this value to 1 to create a log file which shows how each file was renamed.
    SET MakeTranslationFile=0

    :: 0 = Rename the file randomly.
    :: 1 = Prepend the existing file name with randomly generated string.
    SET PrependOnly=0

    :: ————————————————————————–
    :: Do not modify anything below this line unless you know what you are doing.
    :: ————————————————————————–

    SET destDIR=%CD%
    IF NOT {%~f1}=={} SET destDIR=%~f1

    ECHO You are about to randomly rename every file in the following folder:
    ECHO %destDIR%
    ECHO.
    ECHO Warning: This action cannot be undone.
    ECHO Type “OK” to continue.
    SET /P Confirm=
    IF /I NOT {%Confirm%}=={OK} (
    ECHO.
    ECHO Aborting, Press Any Key To Close.
    PAUSE>nul
    GOTO :EOF
    )

    SET TranslationFile= “%destDIR%\Translation.txt”
    IF {%MakeTranslationFile%}=={1} (
    ECHO Original Name = Random Name > %TranslationFile%
    ECHO ————————— >> %TranslationFile%
    )

    CD %destDIR%
    FOR /F “tokens=*” %%A IN (‘DIR /A:-D /B’) DO (
    IF NOT %%A==%~nx0 (
    IF NOT %%A==Translation.txt (
    SET Use=%%~xA
    IF {%PrependOnly%}=={1} SET Use=_%%A
    SET NewName=!RANDOM!-!RANDOM!-!RANDOM!!Use!
    IF {%MakeTranslationFile%}=={1} (
    ECHO %%A = !NewName! >> %TranslationFile%
    ECHO %%A = !NewName!
    )
    RENAME “%%A” “!NewName!”
    )
    )
    )

    ECHO Press Any Key To Close.
    PAUSE>nul

  15. Jason Faulkner

    I have updated the script to include an undo function.
    However, if you delete the translation file you lose the ability to undo the renames.

  16. Robert

    Nice one Jason, thanks for the info. And fighttheright, no one forced you to read, so stop h8in and write your own ‘useful’ post…

  17. Dally

    Thanks a million Jason. I just bulk renamed 700 photos so that I could randomly display them on a TV. Worked a treat!

  18. Micheal

    Right, just to confirm not everyone will use a script like this for malicious reasons. I spent hours looking for a simple filename randomizer until I bumped onto this and this done the job perfectly.

    If someone wants to cause damage or harm to other’s data, there are a million and one ways to do so. Firstly, deleting it all off for a start… or changing its location.. I could go on and on.

    So yeah, despite the previous comments, thanks for this! Cause believe it or not there are people who want to use this for positive reasons.

  19. InstallARheem

    I can’t work out how to use the UNDO function — can anyone tell me how to do this? Thanks in advance!

Get Free Articles in Your Inbox!

Join 134,000 newsletter readers

Email:

Go check your email!