some months ago I wrote such a script. There a two versions using the Finder and Spotlight
Note: No error handling is included
Finder version:
set sourceFolder to (choose folder with prompt "choose source folder")
set sourceFolderName to name of (info for sourceFolder)
set destinationFolder to POSIX path of (choose folder with prompt "choose destination folder")
set folderList to {}
tell application "Finder"
try
set folderList to folders of entire contents of sourceFolder as alias list
on error
set folderList to folders of entire contents of sourceFolder as alias as list
end try
end tell
if folderList is not {} then
set destinationFolder to destinationFolder & sourceFolderName & "/"
do shell script "mkdir " & quoted form of destinationFolder
set pathLength to ((length of POSIX path of sourceFolder) + 1)
repeat with oneFolder in folderList
set restPath to text pathLength thru -1 of POSIX path of (oneFolder as Unicode text)
do shell script "mkdir -p " & quoted form of (destinationFolder & restPath)
end repeat
end if
Spotlight version:
set sourceFolder to (choose folder with prompt "choose source folder")
set sourceFolderName to name of (info for sourceFolder)
set destinationFolder to POSIX path of (choose folder with prompt "choose destination folder")
set folderList to paragraphs of (do shell script "mdfind -onlyin " & quoted form of POSIX path of sourceFolder & " 'kMDItemContentType == \"public.folder\"'")
if folderList is not {} then
set destinationFolder to destinationFolder & sourceFolderName & "/"
do shell script "mkdir " & quoted form of destinationFolder
set pathLength to ((length of POSIX path of sourceFolder) + 1)
repeat with oneFolder in rest of folderList
set restPath to text pathLength thru -1 of POSIX path of (oneFolder as Unicode text)
do shell script "mkdir -p " & quoted form of (destinationFolder & restPath)
end repeat
end if
I am brand new to scripting so please forgive my possible newbie comments. I have been searching and this script seems to be the closest to what I want to do, but not quite there. Can anyone help with getting me to what I am needing.
Here is what I need.
I have software that automatically creates a new folder in a certain location with the name of the current project I am working on. I need to monitor that location and each time a new folder is made in that location the script will make a folder of the exact same name in another location.
I was headed the route of folder actions and maybe this is the right thing, but after searching this forum I see a lot of people bashing folder actions. Not sure Where to head with this.
Thanks for any help,
Josh
Model: PowerPC G5
Browser: Firefox 3.5.2
Operating System: Mac OS X (10.4)