I am trying to filter a list pf 2000 xml files and only move 100 files to a separate folder. I use a text file which contains the list of all the files to be moved. I also need to do the same with a folder with 2000 jpg’s to only move a 100 to a separate folder. The names in the text file are similar to the names of the XML files and Jpeg’s, but wihtout the extenstions. Any suggestion how I can use script to do that?
If I understand you correctly, something like this should work, but it’s not very polished and a few things could throw it of course
set moveData to read (choose file) -- the plain text file containing the files to move
set sourceFolder to choose folder with prompt "Please select your source folder"
set targetFolder to choose folder with prompt "Please select your target folder"
tell application "Finder"
set theFiles to every item of sourceFolder
repeat with aFile in theFiles
set fileName to (name of aFile)
-- "-7" works with .plist files, count the period and characters after it
-- and add one for your purpouses. There are smarter ways to do this though.
if moveData contains (text 1 thru -7 of fileName) then move aFile to targetFolder
end repeat
end tell
James, Thanks for the script below. I ran the script and noticed copied 7 files! I read the script and figured something with the loop.
any way, I think like Mikey suggested, it will help a lot if I give an example.
I have a folder with X number of XML files, all named in this format S-888-60079.xml The range goes from 60079 - 62187. I am only interested in 100 XML files from that range (for example, S-888-60079.xml, S-888-60101.xml, S-888-60105.xml). The XML file I am trying to move to a separate folder are in text file each on a seperate line without the extension .xml:
S-888-60079
S-888-60101
S-888-60105
I also have another foler with a list of covers in the format S-888-60079.jpg
I am trying to do the following, go throught the text file one by one, and if there’s a match with the xml file name and cover name, put them both in a subfolder with the file name. For example, for S-888-60079.xml and S-888-60079.jpg, we will have the folder S-888-60079 with both the (S-888-60079.xml & S-888-60079.jpg) in the folder.