Applescript gurus,
I’ve been looking everywhere for a script for nested folders. We have pics that were saved in nested folders from a digital camera like this:
FOLDER/UNTITLED/DCIM/100NIKON
I need to move the pics from 100NIKON “3 levels up”, in this case FOLDER, then delete UNTITLED.
For what its worth, the name for FOLDER is different, but the nested folders from the camera are all the same.
There has to be a way to automate this. Any help would be greatly appreciated.
Thanks for the quick reply Greg. That’s kind of what I’m looking for.
I know it seems kind of stupid from here.
There are 50,000 pics on a server in many, many folders. Some of them are nested deep in NIKON folders, but some are not. Since all the names for “FOLDER” are different, I need the script/command to work relative to the 100NIKON folder.
The Dogs/labs will have to be handled by yourself as ‘labs’ is the third level up from ‘100NIKON’.
Perfect! That’s exactly what I need it to do, and thats why I used “labs” in the example. It needs to take the pics out of the 100NIKON folder and move it 3 levels up, regardless of what the folder is.
I am definately testing it on a copy. I wouldn’t want to see all my stuff in a box next week because I lost 50,000 pics. :shock:
Frenchc, I’m going to advise you not to use the script I suggested, the ‘rm -f’ is too unfriendly and it can possibly cause you to lose the files. Sorry 'bout that.
I don’t see the original script reply to the request, so I don’t know what was previously suggested, but this seems to fit the bill:
set sourceFolder to choose folder
tell application “Finder”
set destFolder to container of (container of (container of sourceFolder))
move every item of sourceFolder to destFolder
delete (container of (container of sourceFolder))
end tell
It simply uses the Finder’s “container” property to find a parent directory. You don’t need to know the folder names, but you might want to add some error checking to make sure there you’re at least 3 folders deep when you start otherwise the script will fail - a simple try/end try construct should suffice.
Great, thanks Camelot. I’ll work with that one too. Greg took the first script off because it didn’t work as expected. He was using the terminal to find the files.
Camelot, that works very good. One more question:
Instead of having to choose a folder, how could I get the script to sniff out all nested folders named “100NIKON”?
You might not need to resort to recursion. Maybe this will work.
set sourceFolder to "path:to:folder to search:"
tell application "Finder"
set _100NIKON_folders to folders of entire contents of folder sourceFolder whose name is "100NIKON"
end tell
I just now got it. I think by targeting “100NIKON”, it locks up because there are more than one of them. I had to target the first “100NIKON” folder, then delete it.
tell application "Finder"
repeat
if exists folder "100NIKON" in entire contents of folder "foldername" then
set thisfolder_ to first folder of entire contents of folder "foldername" whose name is "100NIKON"
set destFolder to container of (container of (container of thisfolder_))
try
move every item of thisfolder_ to destFolder replacing conflicts
delete (container of container of thisfolder_)
end try
else
display dialog "No more 100NIKON folders"
error number -128
end if
end repeat
end tell
I also found how to quit from an older post of yours. Thanks Rob.