Skip to content

Instantly share code, notes, and snippets.

@hamidne
Created September 16, 2019 02:30
Show Gist options
  • Save hamidne/f5123305a0436a585133fe0041be3898 to your computer and use it in GitHub Desktop.
Save hamidne/f5123305a0436a585133fe0041be3898 to your computer and use it in GitHub Desktop.
Random Rename Files
@ECHO OFF
ECHO Random Names
ECHO Written By: Hamid Nasr
ECHO HamidNE.ir
ECHO.
ECHO Start Random Rename ...
REM Randomly renames every file in a directory.
SETLOCAL EnableExtensions EnableDelayedExpansion
REM 0 = Rename the file randomly.
REM 1 = Prepend the existing file name with randomly generated string.
SET PrependOnly=0
REM 1 = Undo changes according to the translation file.
REM This will only work if the file "__Translation.txt" is in the same folder.
REM If you delete the translaction file, you will not be able to undo the changes!
SET Undo=0
REM --------------------------------------------------------------------------
REM Do not modify anything below this line unless you know what you are doing.
REM --------------------------------------------------------------------------
SET TranslationFile=__Translation.txt
:start
IF NOT {%Undo%}=={1} (
REM Rename files
REM ECHO Original Name/Random Name > %TranslationFile%
REM ECHO ------------------------- >> %TranslationFile%
FOR /F "tokens=*" %%A IN ('DIR /A:-D /B') DO (
IF NOT %%A==%~nx0 (
IF NOT %%A==%TranslationFile% (
SET Use=%%~xA
IF {%PrependOnly%}=={1} SET Use=_%%A
SET NewName=!RANDOM!-!RANDOM!-!RANDOM!!Use!
REM ECHO %%A/!NewName!>> %TranslationFile%
RENAME "%%A" "!NewName!"
)
)
)
) ELSE (
ECHO Undo mode.
REM IF NOT EXIST %TranslationFile% (
REM ECHO Missing translation file: %TranslationFile%
REM PAUSE
REM GOTO :EOF
REM )
FOR /F "skip=2 tokens=1,2 delims=/" %%A IN (%TranslationFile%) DO RENAME "%%B" "%%A"
DEL /F /Q %TranslationFile%
)
ping 1.1.1.1 -n 1 -w 10000>nul
goto start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment