How to batch rename files with a random name??

Discussion in 'macOS' started by amiskwia, Apr 30, 2008.

  1. amiskwia macrumors newbie

    Nov 1, 2007
    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.
  2. MurphyM macrumors 6502

    Dec 29, 2007
    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:

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


    Jan 4, 2008
    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.
  4. amiskwia thread starter macrumors newbie

    Nov 1, 2007
    Seville - Spain
    Hi! I am currently using renamer.exe through VMWare, until I can find a mac app that does the same. Thanks!

    I tried NameMangler, but could not find any random name option :(
  5. riscy macrumors 6502a


    Jan 4, 2008
    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.
  6. Gordy macrumors 6502a

    May 22, 2005
    Bristol, UK
  7. WilWheaton macrumors member

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

    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.
  8. amiskwia thread starter macrumors newbie

    Nov 1, 2007
    Seville - Spain
    Thanks for the tip, but I'm looking for a free solution.

    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.
  9. Darth.Titan macrumors 68030


    Oct 31, 2007
    Austin, TX
    In Terminal first type
    (space after 'cd')
    THEN drag your directory to the Terminal window and press return. That will change to your image directory. Then paste
    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.
  10. amiskwia thread starter macrumors newbie

    Nov 1, 2007
    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.
  11. WilWheaton macrumors member

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

    Nov 2, 2006
    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?
  13. Tumbleweed666 macrumors 68000


    Mar 20, 2009
    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
    >>>Folder B
    >> Folder C
    >>> File 5
    > Folder D

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

    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.
  14. codenewbie macrumors newbie

    Aug 11, 2009
    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?

  15. cekim macrumors newbie

    May 2, 2008
  16. Dybbuk macrumors 6502a


    Aug 8, 2006
  17. angelwatt Moderator emeritus


    Aug 16, 2005
    What OS does have it built-in?
  18. belvdr macrumors 603

    Aug 15, 2005
    No longer logging into MR
    It is and it's called Terminal. Learn those commands and you can do practically anything you wish.

    I don't know of _any_ OS that has a program that automatically does this.
  19. rodman109110 macrumors 6502

    Jun 7, 2007
    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.

    Attached Files:

  20. cekim macrumors newbie

    May 2, 2008
  21. Hyter macrumors newbie

    Jan 24, 2010
    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?
  22. enberg macrumors regular

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


    Jul 28, 2010

    $25 for this application is OUTRAGEOUS !!!!!!!!!!!!

    I'd happily purchase this application for a REASONABLE price.

    It's greedy developers like this that make me glad a simple command line solution was presented. It's no wonder people rip off programs. You developers are just shooting yourselves in the foot.
  24. gwestcott macrumors newbie

    Jan 3, 2010
    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.
  25. GGJstudios macrumors Westmere


    May 16, 2008
    I don't think it's so much the price itself, but the fact that there are free apps can do the same thing.

Share This Page

32 April 30, 2008