Combine files, images, and other files

I need help to combine XML files, covers and images based on ISBN name. I need to group all of them into separate folder, each contains the XML file, cover, and images (if any).
XML files are named with this convention ISBN.xml -->“123456.xml” stored in a separate Folder.
covers are named ISBN.jpg -->“123456” Stored in a separate Folder.
and images are stored in folders with naming convention ISBN “123456”, all folder frouped in one separate Folder.

Any help is greatly appreciated.

Thanks,
Bill

Hi Bill, Im betting the reason you haven’t seen a reply yet is because your post is too vague to really work with. At least it’s too vague for my Vicodin clouded brain.

So you have what? A folder that contains a large number of XML, cover and image files inside other folders? How are things named? I’m confused on that as well. Can you actually type up a real example of exactly what your source folder(s) looks like and what the desired result is?

ok. Let’s make it less vague :slight_smile:

Covers in a separate folder:
978123456789.jpg
978123456781.jpg
978123456782.jpg


XML files in a separate folder:
978123456789.xml
978123456781.xml
978123456782.xml


Imagesa in subfolders a separate folder:
folder–>978123456789
image1.jpg
image2.jpg
image3.jpg


folder–>978123456781
image1.jpg
image2.jpg
image3.jpg

folder–>978123456782
image1.jpg
image2.jpg
image3.jpg

Finally, desired results:

One folder for each ISBN, then all in one folder:

folder–>978123456789
978123456789.xml
Images (folder)
image1.jpg
image2.jpg
image3.jpg

Does that help.

Thanks,
Bill

Here’s my first go at it and it seems to work in my brief testing.

-- set the source paths here or hard code them
set imagesFolder to choose folder with prompt "Please select the 'Images' folder"
set coversFolder to choose folder with prompt "Please select the 'Covers' folder"
set xmlFolder to choose folder with prompt "Please select the 'XML' folder"

tell application "Finder"
	set destFolder to make new folder at desktop with properties {name:"sorted items"}
	move folders of imagesFolder to destFolder
	set imgFolders to folders of destFolder
	repeat with aFolder in imgFolders
		set destImgFolder to make new folder at aFolder with properties {name:"Images"}
		move every file of aFolder to destImgFolder
	end repeat
	my moveFiles(coversFolder, destFolder)
	my moveFiles(xmlFolder, destFolder)
end tell

on moveFiles(sourceFolder, destFolder)
	tell application "Finder"
		set destPath to destFolder as Unicode text
		set fileList to every file of sourceFolder
		repeat with aFile in fileList
			set fileName to text 1 thru -5 of (get name of aFile)
			move aFile to folder (destPath & fileName)
		end repeat
	end tell
end moveFiles

Note that it doesn’t do any checking to make sure things like the “sorted items” folder doesn’t already exist.

James,

all works fine, but the script seems to fail when number of images doesn’t equal or match number of covers and Xml files.

Here’s are some rules you can use for this project:

  1. Number of XML files is almost identical to number of covers
  2. Number of images folder is always less than XML files.
  3. Number of images folder is always less than covers.

Hope this helps.

Give this a try

-- set the source paths here or hard code them
set imagesFolder to choose folder with prompt "Please select the 'Images' folder"
set coversFolder to choose folder with prompt "Please select the 'Covers' folder"
set xmlFolder to choose folder with prompt "Please select the 'XML' folder"

tell application "Finder"
	set destFolder to make new folder at desktop with properties {name:"sorted items"}
	move folders of imagesFolder to destFolder
	set imgFolders to folders of destFolder
	repeat with aFolder in imgFolders
		set destImgFolder to make new folder at aFolder with properties {name:"Images"}
		move every file of aFolder to destImgFolder
	end repeat
	my moveFiles(coversFolder, destFolder)
	my moveFiles(xmlFolder, destFolder)
end tell

on moveFiles(sourceFolder, destFolder)
	tell application "Finder"
		set destPath to destFolder as Unicode text
		set fileList to every file of sourceFolder
		repeat with aFile in fileList
			set fileName to text 1 thru -5 of (get name of aFile)
			try
				make new folder at folder destPath with properties {name:fileName}
			end try
			move aFile to folder (destPath & fileName)
		end repeat
	end tell
end moveFiles

James,

ok. script runs fine, generates folders, combines images with XML files in one folder. However, Covers are created in a separate folder.

Can we have the cover display in the same folder with XML and images (if any). Instead of having 2 folders, one with XML and another with covers.

Thanks again.

Bill

Hmm okay, In one of your earlier examples were you posting actual real names of files? XML, Covers, Images? I made some sample files based on your naming convention and my tests ran fine.

so. what you suggest?

-Bill

Incoming mail

ok. I think I found what went wrong. Covers are named in this convention:
ISBN_0000.jpg
so, if we have:
9781439350997.xml & 9781439350997_0000.jpg, the script creates a new folder 9781439350997 which includes 9781439350997.xml. That is correct so far.
Howver, it creates a new folder and call it 9781439350997_0000 which includes the cover 9781439350997_0000.jpg

Thanks,
Bill

forgot to mention, covers should go the same folder as Images.

So, final output format:

ISBN (folder)
ISBN.xml (file)
Images (Folder)
ISBN_0000.jpg (cover)
image1.jpg
image2.jpg


thanks,
Bill

and what did you mean by an incoming mail? not sure if I get that.

I sent you an email thru the forum here. Whatever email address you registered with should have an email from me.

James. check your mail. please send to new account.