How to rewrite the first 3 letters of file name
- Using set alphabet: ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 to randomise characters
- Targeting all files of a particular extension in a folder *.ext
- Duplication of 3 characters by chance does not matter (46,656 variables already)
- Batch script solution to run in a windows environment.
- Prefer script to be simple to reduce run time.
Suggested code and breakdown. Note: I still have no idea how to code.
032_name.ext 039_name.ext 0D8_name.ext 333_other.txt
Write Over the top of first three characters
D7K_name.ext L2V_name.ext 720_name.ext 333_other.txt
Make batch file (SetRename.bat or SetRename.cmd) then run command like:
SetRename %r *.ext /or/ SetRename %r3%name% *.ext /or/ SetRename
Code 1 adapted from DavidPostill, example of full solution
@echo off setlocal enabledelayedexpansion rem initialise counter set "alphabet=A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9" rem process jpg and png files for /f "usebackq tokens=*" %%i in (`dir /b *.ext *.ex2`) do ( rem split into name and extension set _name=[reduce 3 characters]]%%~ni set _ext=%%~xi rem do the rename ren "%%i" "!y!-!_name!-!_ext!" increment counter set /alphabet "%Random%" ) endlocal
Code 2 adaptated from 3 SU posts
@echo off setlocal enableextensions enabledelayedexpansion set "alphabet=A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9" for %%a in (%alphabet%) do ( set "a.!name!=%%a" set o=-%3 [reduce by 3] ) set "y=" for /l %%a in (1 1 3) do ( set /a "r=!random!" for %%b do set "y=!-%3!!r!!name!" ) echo(%y% endlocal
- SU File rename with suffix as 01 02 03 04 etc (and Further Reading)
- SU How do I isolate filename and extension from %1?
- SU Rename files by command line
- SU Rename Files Random Batch File
- SU - How do I remove the same part of a file name
- SU Command Prompt Rename Prefix
- Stack Overflow on Random Strings: Link 1 Link 2 Link 3
- ss64 - Random Syntax
- ss64 - REN Rename Command
- wikibooks - Windows Programming/Programming CMD
- Informit - Windows Batch Files
- techguy - Random Numbers and Letters