Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I need to write a batch file that goes into a folder and randomly swaps (renames) all the filenames. This folder has about 1000 files. So it is acceptable if there are few misses.

share|improve this question
I have to ask, why? And when you say randomly swaps, do you mean haphazardly or randomly? Do all the files make up a set of filenames that must remain constant? –  Raystafarian Jul 23 '13 at 0:28
related take a look and try it out for yourself, then come back and tell us where you're stuck. –  Raystafarian Jul 23 '13 at 0:31
"Do all the files make up a set of filenames that must remain constant" - yes, thats the tricky part. They are image sequences that need to randomized for each iteration. –  MD Luffy Jul 23 '13 at 0:55
This random swapping reminds me of the ripper virus, which swapped information to corrupt a disk slowly. I would be wary of answering this question, as it seems to have a malicious intent (even if op wants to do this in jest) –  SeanC Jul 31 '13 at 13:57
@SeanCheshire dude seriously ? You didnt bother to ask my use case but make ridiculous allegations like these. (Its related to making slideshow videos with ffmpeg for those who care) –  MD Luffy Aug 5 '13 at 21:43

1 Answer 1

Appends random number to file name and preserves extension:

@echo off
setlocal enabledelayedexpansion

for %%F in ("C:\my photos\*.*") do ( 
    rename "%%~fF" "%%~nF!random!%%~xF" || (
        echo ERROR: "%%~fF"

exit /B 0
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.