Sort files into folders according to name?
Hello!
I have a set of static folders already created, and I am trying to sort files into them according to name. The files follow the format "Last Name, First Name.csv" and the subfolders are named "Last Name, First Name Folder" The subfolders are in a different directory from the source folder (with all the to-be-sorted files).
I've tried to Frankenstein some other apple scripts, but having trouble moving the file into the corresponding specific folder in a different directory.
on run {input, parameters}
set output to {}
repeat with anItem in the input
set anItem to anItem as text
tell application "System Events" to tell disk itemanItem
set theContainer to path of container
set {theName, theExtension} to {name, name extension}
end tell
if theExtension is in {missing value, ""} then
set theExtension to ""
else
set theExtension to "." & theExtension
end if
set theName to text 1 thru -((counttheExtension) + 1) of theName-- the name part
tell application "System Events" to set {Nm, Ex, pPath} to anItem's {name, name extension, POSIX path of container}
set BN to text 1 thru ((get offsetof "." & ExinNm) - 1) of Nm
set thePath to (pPath & "/" & BN & "/" as text) -- THIS SHOULD BE WHERE I CAN ENTER THE OTHER DIRECTORY INFO, BUT ERRORS ABOUND
do shell script "mkdir -p " & quoted form of thePath
delay 0.5
tell application "Finder" to moveaFiletoPOSIX filethePath
end repeat
return input-- or output
end run
iMac, OS X Yosemite (10.10.1)