How to batch rename files with a random name??

amiskwia

macrumors newbie
Original poster
Nov 1, 2007
24
0
Seville - Spain
Hello everybody!!! Here is my situation:
I have a digital photo frame to see my pictures, but it only plays photos secuencially, it can't be set on "shuffle". So if I could rename the photos with random names, then the effect would be the same, as I would be seeing them in "shuffle".
I know automator can rename files, and there are many many apps that also rename, but I haven't found one that can give the files a random name!
Any suggestions??
Thank you.
 

MurphyM

macrumors 6502
Dec 29, 2007
263
0
I needed to do the same thing for the same exact reason. I made this shell script that did it but it must have messed up resource forks or something because it broke all my jpg files! (I had copies)

Anyway, if you have access to Windows this is a really easy way to do it:
http://www.winsite.com/bin/Info?2000000035423

It's called renamer.exe and it can add a random number to file names in a batch.
 

riscy

macrumors 6502a
Jan 4, 2008
737
3
China
Image Well does this - it has a little icon in the top left corner for creating random file names. But I don't think it does batch.

You can find it here

NameMangler does do batch renaming and I think there is probably an advanced option where you could randomise the names (although I have never tried to do it), the link can be found on the site in my sig.
 

amiskwia

macrumors newbie
Original poster
Nov 1, 2007
24
0
Seville - Spain
I needed to do the same thing for the same exact reason. I made this shell script that did it but it must have messed up resource forks or something because it broke all my jpg files! (I had copies)

Anyway, if you have access to Windows this is a really easy way to do it:
http://www.winsite.com/bin/Info?2000000035423

It's called renamer.exe and it can add a random number to file names in a batch.
Hi! I am currently using renamer.exe through VMWare, until I can find a mac app that does the same. Thanks!

Image Well does this - it has a little icon in the top left corner for creating random file names. But I don't think it does batch.

You can find it here

NameMangler does do batch renaming and I think there is probably an advanced option where you could randomise the names (although I have never tried to do it), the link can be found on the site in my sig.
I tried NameMangler, but could not find any random name option :(
 

riscy

macrumors 6502a
Jan 4, 2008
737
3
China
If you click at the top and change to advanced, you have an option to do some coding there, so I am sure you could look at the example scripts given, but that is too technical for me, sorry and maybe also look for a NameMagler forum or contact the author, I am sure it is possible as it is a great app.
I tried NameMangler, but could not find any random name option :(
 

WilWheaton

macrumors member
Feb 21, 2008
33
0
If you're ok with pasting something into the command line do this

Code:
for i in *.jpg; do mv $i $RANDOM.jpg; done
just open the terminal, drag your folder in to the terminal window to change the active directory in the terminal, and paste that in press enter.
 

amiskwia

macrumors newbie
Original poster
Nov 1, 2007
24
0
Seville - Spain
Try renamer4mac that may do the job
Thanks for the tip, but I'm looking for a free solution.

If you're ok with pasting something into the command line do this

Code:
for i in *.jpg; do mv $i $RANDOM.jpg; done
just open the terminal, drag your folder in to the terminal window to change the active directory in the terminal, and paste that in press enter.
I open a terminal window, drag the folder inside, paste that code and press enter. I get the error:

-bash: syntax error near unexpected token `do'

I have no clue how to use terminal commands, so I don't know what's wrong.
Thanks for the help.
 

Darth.Titan

macrumors 68030
Oct 31, 2007
2,740
451
Austin, TX
If you're ok with pasting something into the command line do this

Code:
for i in *.jpg; do mv $i $RANDOM.jpg; done
just open the terminal, drag your folder in to the terminal window to change the active directory in the terminal, and paste that in press enter.
In Terminal first type
Code:
cd
(space after 'cd')
THEN drag your directory to the Terminal window and press return. That will change to your image directory. Then paste
Code:
for i in *.jpg; do mv $i $RANDOM.jpg; done
just like Wil said.
I just tried it and it works as you'd expect.
 

amiskwia

macrumors newbie
Original poster
Nov 1, 2007
24
0
Seville - Spain
Now it worked. With the cd space thing and I had to type JPG in capital leters for it to work, because all my pics extension are .JPG and not .jpg

Now I'll investigate a bit and see if I can put this into an automator workflow or an applescript or something.

Thank you very much for all the help.
 

WilWheaton

macrumors member
Feb 21, 2008
33
0
Thanks for dropping the ball I left there Darth.Titan, and I'm glad you got it to work amiskwia :D
 

clindner

macrumors regular
Nov 2, 2006
134
1
So, this is a handy one line script, but what happens if the RANDOM number generated is the same as one previously generated. Will the previous file be overwritten, or will the old file retain its current name?
 

Tumbleweed666

macrumors 68000
Mar 20, 2009
1,659
63
Near London, UK.
Waking this thread up as I have the same requirement and hoping someone good at scripts cam answer this;.

The above script works only for a single directory level (I just tried it) and though there is the issue of what happens if the random name is the same presumably that can be managed with an 'if not exists' or whatever the equivalent is for Mac, but I have an additional requirement that I am hoping a script 'whiz' can come up with an easy answer for.

If the original files are in a more complex directory structure than a single level , the script doesnt work, it doesn't rename files in "sub folders". What I need is to copy all the files into a 'flat' directory structure and rename.
Example, starting with;

Top Folder
>Folder A
>>File01
>>File02
>>>Folder B
>>>>File03
>> Folder C
>>> File 5
> Folder D
etc

I'd like to get to
Top Folder
random file name 1
random file name 2
random file name 3
etc

It doesn't matter if the original folders are left around empty.

Anyone care to have a go at a script?

I have a similar conversation over here so best to reply there should anyone be so inclined as to reply. Thanks.
 

codenewbie

macrumors newbie
Aug 11, 2009
11
0
Where does this output to?

Sorry to re-ignite a thread from some time ago, but trying to use the code suggested and unsure whether the code is executing, or if so, where it is placing the output.

I have navigated through to the folder in which the files to rename are located. I am then using:

for i in *.jpg; do mv $i $RANDOM.jpg; done

as suggested by Wil. This leads to a repeated screen display of:

usage: mv [-f | -i | -n] [-v] source target
mv [-f | -i | -n] [-v] source ... directory

I have not been able to identify any output from the process in the directory.

If I change the file extension I get a message to say file not found, so the issue does not appear to be identification of files.

Sure this is a simple fix, but no idea where to start. Can anyone help?

Thanks
 

rodman109110

macrumors 6502
Jun 7, 2007
310
0
This site offers some services and automations. the have a rename selected files service that will do what you want i think.

the attachment shows how it will look when installed. you just select the items you want renamed, right click, and go down to Services and than over to Disk item - Rename selected items and there will be some options to rename the files.

http://www.macosxautomation.com/services/download/index.html
 

Attachments

Hyter

macrumors newbie
Jan 24, 2010
1
0
So, this is a handy one line script, but what happens if the RANDOM number generated is the same as one previously generated. Will the previous file be overwritten, or will the old file retain its current name?
It unfortunately does overwrite files because I am having this problem. :-/
Does anyone know of an Applescript to check to make sure it doesn't overwrite?
 

enberg

macrumors regular
Jan 13, 2010
204
0
Code:
for i in *.jpg; do mv $i `od -An -N2 -i /dev/random`.jpg; done
note that those are grave accents, not apostrophes.
 

gwestcott

macrumors newbie
Jan 3, 2010
4
0
I think the price of that application is VERY reasonable. In the way past, everything was hundreds of dollars. I think $25 is very affordable. These days we are so spoiled by the low prices that we don't appreciate when something is so inexpensive. We need to support those people who work hard at making them. They are not trying to rip us off. They are just trying to make a living.
 

GGJstudios

macrumors Westmere
May 16, 2008
44,428
796
I think the price of that application is VERY reasonable. In the way past, everything was hundreds of dollars. I think $25 is very affordable. These days we are so spoiled by the low prices that we don't appreciate when something is so inexpensive. We need to support those people who work hard at making them. They are not trying to rip us off. They are just trying to make a living.
I don't think it's so much the price itself, but the fact that there are free apps can do the same thing.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.