Hey folks,
Im trying to create a script that searches a parent folder with a particular subfolder structure for any files marked with a “+” and moves them to a new parent folder, maintaining the same subfolder structure under the new parent folder for each found and moved file. Ive come across 3 problems in the draft I have so far. In order of importance, they are:
- I cant figure out how to get the path names of each found file entered into the shell script (that moves the files to the new location) as text, therefore creating the appropriate directory structure for each moved file in its new location.
- I’m not sure how to search the subfolders of the source folder for files as well as the source folder itself
- something is wrong with the error counter, it always shows the amount of files that have moved.
I am pretty much a novice at scripting and this is a modified version of another script I found on this forum. Thanks in advance for any help!
What i have so far:
property destinationFolder : missing value
property sourceFolder : missing value
– Locate the source folder–
if sourceFolder = missing value then set sourceFolder to choose folder with prompt “Select source folder:”
– Locate the destination folder
if destinationFolder = missing value then set destinationFolder to choose folder with prompt “Select destination folder:”
display dialog "This script will move and organize the original images of the source folder to the destination folder. After moving and organizing the files in the source folder they will be deleted from the folder. Once Move Button is hit, there is no redo. " buttons {“Cancel”, “Move”} default button 1 with icon note
tell application “Finder” to set theFiles to (get files of sourceFolder whose name contains “+”)
set theCount to count theFiles
set x to 0 – error counter
set POSIX_destinationFolder to POSIX path of destinationFolder
set POSIX_sourceFolder to POSIX path of sourceFolder
repeat with eachFile in theFiles
tell application “Finder”
set fName to name of eachFile
–this is where I need help defining a “folderPath” variable whose value would be the POSIX path of each selected file as a string (so it can be entered into the shell script below). I thought it would be something like: set folderPath to POSIX path of eachFile
end tell
try
do shell script "mv " & quoted form of POSIX path of (eachFile as alias) & space & quoted form of (POSIX_destinationFolder & “/” & folderPath & “/” & fName)
–this shell script section works if you take out the folderPath variable part of it. It just takes the files with plusses and moves them to the new parent directory. I need to recreate same subfolder structure that the file originally existed in though, just under the new parent
set x to x + 1
end try
end repeat
set theMsg to “Script completed.” & return
if theCount = 0 then
set theMsg to theMsg & “No items were moved.”
else if theCount = 1 then
set theMsg to theMsg & “1 item was moved.”
else if theCount > 1 then
set theMsg to theMsg & theCount & " items were moved."
end if
display dialog theMsg & return & x & " error(s)" buttons {“OK”} default button “OK”