Advertisement
Guest User

Untitled

a guest
Jan 9th, 2021
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 2.04 KB | None | 0 0
  1. @ECHO OFF
  2. ECHO Random Names
  3. ECHO Written By: Jason Faulkner, upgraded by eternalko
  4. ECHO HowToGeek.com
  5. ECHO.
  6. ECHO.
  7.  
  8. REM Randomly renames every file in a directory.
  9.  
  10. SETLOCAL EnableExtensions EnableDelayedExpansion
  11.  
  12. REM 0 = Rename the file randomly.
  13. REM 1 = Prepend the existing file name with randomly generated string.
  14. SET PrependOnly=0
  15.  
  16. REM 1 = Undo changes according to the translation file.
  17. REM This will only work if the file "__Translation.txt" is in the same folder.
  18. REM If you delete the translaction file, you will not be able to undo the changes!
  19. REM SET Undo=1
  20.  
  21.  
  22. REM --------------------------------------------------------------------------
  23. REM Do not modify anything below this line unless you know what you are doing.
  24. REM --------------------------------------------------------------------------
  25.  
  26. SET TranslationFile=__Translation.txt
  27.  
  28. COLOR 0A
  29.  
  30.  
  31. IF EXIST %TranslationFile% (
  32.     SET Undo=1
  33. ) ELSE (
  34.     SET Undo=0
  35. )
  36.  
  37.  
  38.  
  39. IF NOT {%Undo%}=={1} (
  40.     REM Rename files
  41.     ECHO You are about to randomly rename every file in the following folder:
  42.     ECHO %~dp0
  43.     ECHO.
  44.  
  45.     ECHO A file named [%TranslationFile%] will be created which allows you to undo this.
  46.  
  47.     ECHO Warning: If [%TranslationFile%] is lost/deleted, this action cannot be undone.
  48.     ECHO Proceed? y/n
  49.     SET /P Confirm=
  50.     IF /I NOT {!Confirm!}=={y} (
  51.         ECHO.
  52.         ECHO Aborting.
  53.         GOTO :EOF
  54.     )
  55.  
  56.     ECHO Original Name/Random Name > %TranslationFile%
  57.     ECHO ------------------------- >> %TranslationFile%
  58.  
  59.     FOR /F "tokens=*" %%A IN ('DIR /A:-D /B') DO (
  60.         IF NOT %%A==%~nx0 (
  61.             IF NOT %%A==%TranslationFile% (
  62.                 SET Use=%%~xA
  63.                 IF {%PrependOnly%}=={1} SET Use=_%%A
  64.                
  65.                 SET NewName=!RANDOM!-!RANDOM!-!RANDOM!!Use!
  66.                 ECHO %%A/!NewName!>> %TranslationFile%
  67.                
  68.                 RENAME "%%A" "!NewName!"
  69.             )
  70.         )
  71.     )
  72. ) ELSE (
  73.     ECHO Undo mode.
  74.     IF NOT EXIST %TranslationFile% (
  75.         ECHO Missing translation file: %TranslationFile%
  76.         PAUSE
  77.         GOTO :EOF
  78.     )
  79.     FOR /F "skip=2 tokens=1,2 delims=/" %%A IN (%TranslationFile%) DO RENAME "%%B" "%%A"
  80.     DEL /F /Q %TranslationFile%
  81. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement