Generate Random Filenames in DOS

without comments

From the Great Bucket of Random Things, here’s a script for generating a random numeric filename for each JPG in a folder using DOS Batch scripting:

Note: The below does not work properly for filenames with spaces, sorry. I’m sure it wouldn’t be too hard to fix it, but as this script has already served its purpose for me, alas, it will remain as it is…

@echo off
setlocal
 
for /f %%i in ('dir /b *.jpg') do call :resize %%i
 
:resize
:resize_1
    if "%1"=="" goto :EOF
    set filename=%random%.jpg
    if EXIST %filename% goto resize_1 
    rename %1 %filename%
    echo Renamed '%1' to '%filename%'
goto :EOF

I posted this on the wiki as well since I need to write something using a DOS batch with the exact same frequency with which I completely forget how to do so.

Written by arthur

September 6th, 2011 at 2:38 pm

 

Leave a Reply