Hey all, I’ve found myself working with applescript for about a month now. I’m working on a solution, but I can’t seem to break through.
The solution will move a file, from a source directory, to a subfolder of a destination directory. The file and subfolder have partially matching names.
So, 3 important items:
-A file, with a naming format like this: “TV1001_JPartial_String_Match_Here_FILE_34059345.pdf”
-A source directory. The name of this is not relevant, as I’ll just declare this folder, and not do anything else with it.
-A destination subdirectory, with a naming format like this:
“55555_JPartial_String_Match_Here_FOLDER_390489348”. The file will be placed in the matching subdirectory.
So, moving into a specific directory, if there is a partial match. I’ve gotten a decent part of the way. Here is my current script.
property delim : "_"
set myStrings to ¬
"TV1001_JPartial_String_Match_Here_FILE_34059345"
set strLength to count of characters of myStrings
set {TID, AppleScript's text item delimiters} to ¬
{AppleScript's text item delimiters, delim}
set sTrim1 to text 9 thru (strLength + (offset of "J" in text)) of myStrings
set newStringsList to {}
repeat with thisString in paragraphs of sTrim1
set delimCount to (length of text items of thisString) - 1
if delimCount ≥ 3 then
set thisString to text items 1 thru 4 of thisString
set thisString to thisString as string
copy thisString to end of newStringsList
end if
end repeat
set AppleScript's text item delimiters to linefeed & linefeed
set myNewStrings to newStringsList as text
set AppleScript's text item delimiters to TID
set sourceDir to "~/Desktop/sourceDir"
set destDir to "~/Desktop/DestDir"
set subString to myNewStrings
do shell script "/usr/bin/find " & sourceDir & " -depth 1 -type d -name '*" & subString & "*' -exec mv {} " & destDir & " \\; "
display dialog myNewStrings
As you can see, I’m using a shell script to do the moving part, and finding the potential match before that.
Any ideas?