Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

nickwaite

macrumors newbie
Original poster
Mar 28, 2012
2
0
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
 
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);
		}
	}

}
?>
 
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

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
 
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
 
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.