Want to highlight a helpful answer? Upvote!

Did someone help you, or did an answer or User Tip resolve your issue? Upvote by selecting the upvote arrow. Your feedback helps others! Learn more about when to upvote >

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

File Sorter, all working need it to anything left behind"PLEASE"

I have this script, and it sorts the files to move into the other folders of the desktop, I now need to add a wildcard that if it doesn't fit the files with the prefixes then move them to folder that begins with "Mik


Is this something that can be easy to do?


Many Thanks


Matt




# the file matrix is a record of {destination folder name, {list of file prefixes to move}}

set fileMatrix to

{folderName:"2_do_BHS", prefixes:{"BH70", "SM70", "AL70", "BH11"}}, ¬

{folderName:"2_do_Bu", prefixes:{"BU40", "BU11"}}, ¬

{folderName:"2_do_Ca", prefixes:{"CW"}}, ¬

{folderName:"2_do_Da", prefixes:{"ES20", "AM20"}}, ¬

{folderName:"2_do_Di", prefixes:{"DV25", "DV11"}}, ¬

{folderName:"2_do_Do", prefixes:{"DJ30", "RA30", "DJ11"}}, ¬

{folderName:"2_do_In", prefixes:{"GT55", "CC55"}}, ¬

{folderName:"2_do_Fr", prefixes:{"FR10", "FR11"}}, ¬

{folderName:"2_do_No", prefixes:{"TM17", "NN_"}}, ¬

{folderName:"2_do_Ma", prefixes:{"MA65", "MF65", "FI65", "MC65", "MH65", "MB65"}}, ¬

{folderName:"2_do_Pr", prefixes:{"PR_"}}, ¬

{folderName:"2_do_To", prefixes:{"TM15", "TM11"}}, ¬

{folderName:"2_do_Wa", prefixes:{"WA35", "WA11"}}, ¬

{folderName:"2_do_Se", prefixes:{"SE_"}}}


tell application "Finder"

set theHotFolder to folder "StudioA:Users:StudioA:Pictures:HotFolder2Do"


repeat with matrixItem in fileMatrix-- look for folder

set destinationFolder to (folders of desktop whose name starts with folderName of matrixItem)

if destinationFolder is not {} then -- found one

set destinationFolder to first item of destinationFolder-- only one destination


repeat with aPrefix in prefixes of matrixItem-- look for files

set theFiles to (files of theHotFolder whose name starts with aPrefix) as alias list


if theFiles is not {} then repeat with aFile in theFiles -- move files

try


moveaFiletodestinationFolder

on error errmessnumbererrnum-- oops (should probably check for a specific error number)

log "Error " & errnum & " moving file: " & errmess

set newName to my getUniqueName(aFile, destinationFolder)

set name of aFile to "this is a unique name" -- or whatever


moveaFiletodestinationFolder

set name of aFile to newName

end try

end repeat

end repeat

end if

end repeat

end tell



to getUniqueName(someFile, someFolder)


(*

check if someFile exists in someFolder, creating a new unique file name (if needed) by adding a suffix

parameters - someFile [mixed]: a source file path

someFolder [mixed]: a folder to check

returns [list]: a unique file name and extension

*)

set {counter, suffixes, divider} to {0, "abcdefghijklmnopqrstuvwxyz", "_"}

set someFile to someFile as text-- System Events will use both Finder and POSIX text


tell application "System Events" to tell disk item someFile to set {theName, theExtension} to {name, name extension}

if theExtension is not "" then set theExtension to "." & theExtension

set theName to text 1 thru -((length of theExtension) + 1) of theName -- just the name part


set newName to theName & theExtension

tell application "System Events" to tell (get name of files of folder (someFolder as text))

repeat while it contains newName

set counter to counter + 1 -- hopefully there aren't more than 26 duplicates (numbers are easier)

set newName to theName & divider & (itemcounter of suffixes) & theExtension

end repeat

end tell


return newName

end getUniqueName

iMac, Mac OS X (10.6.8)

Posted on Mar 8, 2013 5:53 AM

Reply
Question marked as Best reply

Posted on Mar 8, 2013 6:51 AM

add the item {folderName:"Mik", prefixes:{""}} to the end of fileMatrix variable. After it's done processing all the other elements it will look for files that are prefixed with an empty string (i.e. every file) and move those.

2 replies

File Sorter, all working need it to anything left behind"PLEASE"

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.