Batch Processing Image Nightmare - Please Help If You Can!

Discussion in 'Web Design and Development' started by nickwaite, Mar 28, 2012.

  1. nickwaite macrumors newbie

    Joined:
    Mar 28, 2012
    #1
    Hi,

    Pulling my hair out here. I have to rename a series of images, all placed in a folder containing about 100 sub-folders containing the images. Each sub-folder contains a maximum of five images and I need to retain the folder name in the new file names.

    Example:

    'Fruit' folder contains images:

    1.png
    2.png
    3.png

    I need the file names to be saved in a new group folder named as:

    Fruit-1.png
    Fruit-2.png
    Fruit-3.png

    If I could select multiple folders to achieve this it would be amazing, but even if I have to do one by one without having to type the folder name in every time it would be good!

    Any help greatly appreciated. Picturesque, Automator and Photoshop can't do it unless I'm missing something?

    Thanks, Nick
     
  2. frocco macrumors 6502

    frocco

    Joined:
    Jan 27, 2009
    #2
    Try This

    Code:
    <?php
    //Before
    //folder
    //  folder1
    //		1.jpg
    //		2.jpg
    //  folder2
    //		1.jpg
    //		2.jpg
    //********************
    //After
    //folder
    //  folder1
    //		folder1_1.jpg
    //		folder1_2.jpg
    //  folder2
    //		folder2_1.jpg
    //		folder2_2.jpg
    foreach(glob('c:/folder/*', GLOB_ONLYDIR) as $dir)
    {
    	$dirs =  explode("/",$dir);
    	$files = scandir($dir);
    	foreach($files as $file)
    	{
    		if (!is_dir($file))
    		{
    			$old_name = $dir . '/' .$file;
    			$new_name = $dir . '/' . $dirs[2].'-'.$file;
    			rename($old_name, $new_name);
    		}
    	}
    
    }
    ?>
    
     
  3. chrysrobyn macrumors member

    Joined:
    May 9, 2003
    Location:
    Austin, TX
    #3
    for FOLDER in * ; do cd $FOLDER;for FILENAME in * ; do mv $FILENAME $FOLDER-$FILENAME;done;cd ..;done

    to test before executing, do this one
    for FOLDER in * ; do cd $FOLDER;for FILENAME in * ; do echo $FOLDER-$FILENAME;done;cd ..;done
     
  4. nickwaite thread starter macrumors newbie

    Joined:
    Mar 28, 2012
    #4
    Thanks!

    I'll try this today, though it looks a bit more complicated than the usual stuff I do! I assume * is replaced with the directory address of the folder? Sorry, but a bit of an amateur with this stuff! I'll let you know if it works...

    Thanks,

    Nick
     
  5. lighthouse_man macrumors 6502a

    Joined:
    Mar 13, 2005
    #5
    This can be easily done with Automator. Google "automator rename files" and it'll yield many results including some videos that explain how it's done.
     

Share This Page