How to move files instead of deleting in Applescript
Hello!
I found this awesome code by SGIII in an older thread and it works great to delete RAW files that do not match JPG in another folder. However for safety it would be perfect if the script could:
- Create a new subfolder "RAW files to delete" in the RAW folder
- Move those RAW files that do not have a equivalent JPG file to that folder
I tried to google and change the script, but since I'm a total newbie I couldn't do it.
That would make it more safe, since I otherwise could accidentally delete some files that are still needed.
Here is the script:
tell application "Finder"
set fr to choose folder with prompt "Choose subfolder with RAW files"
set fj to choose folder with prompt "Choose subfolder with corresponding JPEG files"
set {rFiles, jFiles} to {fr's files as alias list, fj's files as alias list}
set {rNames, jNames} to {my stripExt(rFiles), my stripExt(jFiles)}
repeat with i from 1 to count rFiles
if rNames's item i is not in jNames then delete rFiles's item i
end repeat
end tell
to stripExt(fileList) -- removes extension so names can be compared
set nn to {}
tell application "Finder"
repeat with f in fileList
set nn's end to ¬
(f's name as text)'s text 1 thru -(((f's name extension as text)'s length) + 2)
end repeat
end tell
return nn
end stripExt
I would really appreciate if somebody could help me out on with this :)
Macbook (2015 or later)