1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Batch Rename Images On A Server

Discussion in 'PHP' started by nOR, Feb 22, 2006.

  1. #1
    Is their a script that I can put in a directory of images on my webserver, that will allow me to batch re-name them all? :confused:
     
    nOR, Feb 22, 2006 IP
  2. jedibusiness

    jedibusiness Well-Known Member

    Messages:
    147
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    108
    #2
    I can suggest a few programs for download for windows that would basically do that. Off the top of my head, I don't know of a mass file renamer script.
     
    jedibusiness, Feb 23, 2006 IP
    nOR likes this.
  3. nOR

    nOR Peon

    Messages:
    281
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks for the reply, but im trying to do it so I dont have to reload all my pictures to the server.

    Thanks again :cool:
     
    nOR, Feb 23, 2006 IP
  4. maxim_al

    maxim_al Peon

    Messages:
    78
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    maxim_al, Feb 24, 2006 IP
    nOR likes this.
  5. nOR

    nOR Peon

    Messages:
    281
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Thank you maxim_al, I checked it out and looks like something I can do. :D
     
    nOR, Feb 24, 2006 IP
  6. blinxdk

    blinxdk Peon

    Messages:
    660
    Likes Received:
    27
    Best Answers:
    0
    Trophy Points:
    0
    #6
    If the OS is Unix based, there are already all sorts of tools for that.

    Is there some pattern to how you want them renamed? I'd be happy to help you script it then.
     
    blinxdk, Feb 24, 2006 IP
  7. nOR

    nOR Peon

    Messages:
    281
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Whoa I wasn't expecting individual help on it, but that's great if its something simple. (yes its on linux)

    I'm at work right now so I can't start with the PHP scripting, but basically on my photography site okinawa-photography , the pictures on the server are all named with camera's default naming, ie. DSCP0001. Instead of uploading all new pictures again, I would just like to maybe rename them according to the directory they are in (so if someone searched for "okinawa beach" they would be listed) So for example something like: okinawa_beach_daytime_001.jpg. Easy enough to implement?
     
    nOR, Feb 24, 2006 IP
  8. blinxdk

    blinxdk Peon

    Messages:
    660
    Likes Received:
    27
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Ok, see I'm currently in a directory called okinawabeach that contains some photos called DSCP0001.jpg DSCP0002.jpg etc.

    mrspanky@online-42:~/phototest/okinawabeach$ ls
    DSCP0001.jpg DSCP0003.jpg DSCP0005.jpg DSCP0007.jpg
    DSCP0002.jpg DSCP0004.jpg DSCP0006.jpg DSCP0008.jpg

    So if I do:

    mrspanky@online-42:~/phototest/okinawabeach$ for i in * ; do mv $i okinawa_beach_daytime_`echo $i | awk -FDSCP '{print $2}'`; done

    The result is this:
    mrspanky@online-42:~/phototest/okinawabeach$ ls
    okinawa_beach_daytime_0001.jpg okinawa_beach_daytime_0005.jpg
    okinawa_beach_daytime_0002.jpg okinawa_beach_daytime_0006.jpg
    okinawa_beach_daytime_0003.jpg okinawa_beach_daytime_0007.jpg
    okinawa_beach_daytime_0004.jpg okinawa_beach_daytime_0008.jpg
     
    blinxdk, Feb 24, 2006 IP
  9. blinxdk

    blinxdk Peon

    Messages:
    660
    Likes Received:
    27
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Basicly all you go to do is change to the directory and run
    for i in * ; do mv $i okinawa_beach_daytime_`echo $i | awk -FDSCP '{print $2}'`; done
    Code (markup):
    You can ofcouse change okinawa_beach_daytime to something else in that line - you could also change it to correspond to the directory you are currently in but this is just a fast sollution. If you need to change it to be more automated, just let me know.

    Oh and ofcouse also change awk -FDSCP to something else if your files doesn't start with DSCP.
     
    blinxdk, Feb 24, 2006 IP
  10. blinxdk

    blinxdk Peon

    Messages:
    660
    Likes Received:
    27
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Allright - this uses the current work directory:

    for i in * ; do echo mv $i `pwd | sed -e "s/.*\/\([^/]*\)$/\1/"`_`echo $i | awk -FDSCP '{print $2}'`; done

    Make a copy of the directory and give it a test run first :)
     
    blinxdk, Feb 24, 2006 IP
    nOR likes this.
  11. nOR

    nOR Peon

    Messages:
    281
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    0
    #11
    Thank you so much for the excellent help. I will try this as soon as I get home. I should have no problems with your great explanation :D
     
    nOR, Feb 24, 2006 IP