1.

Solve : random rename help?

Answer»

Ok, so I was trying to make a BATCH file to rename all pictures in a folder to a random number between 1 and 29, the only problem is, it'll only rename one picture and it says "A duplicate file name exists, or the file cannot be found. So I tried to do a loop code but it did the same thing, except it repeated that message over and over and over. Here is the code.

@echo off
set /A random=%random% %% 29
set /A random=%random% + 1
ren *.gif %random%.gif
pause
exitThis example assumes the batch file is in the same folder as the pictures:

Code: [Select]@echo off
setlocal enabledelayedexpansion
for /f "tokens=* delims=" %%x in ('dir /b *.gif') do (
set rnd=!random!
set /A rnd=!rnd! %% 29
set /A rnd=!rnd! + 1
ren %%x !rnd!.gif
)

The duplicate file problem still exists. The random number generator does not keep track of previous numbers pulled. Not only is it possible to pull duplicate numbers, it's EVEN more likely by limiting the pool to 29 numbers.

From reading other posts, there seems to be a whole lot of fascination in random this week. Quote from: dragonmaster2091 on January 25, 2008, 08:06:31 PM

Ok, so I was trying to make a batch file to rename all pictures in a folder to a random number ...

Is RENAMING the goal here, or is randomness via a batch file more important?

For what it is worth: Irfanview has a batch rename function. It is a very nice program for handling pictures, etc.
Irfanview is free.

http://www.irfanview.com

Thanks Sidewinder, your solution did the trick to all but one picture, but then all I had to do was change one picture's name to the number that wasn't on there lol.learning....


Discussion

No Comment Found