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