I have created a recursive script to take a source path and copy the entire folder structure to a destination folder. The problem is the handler for creating the subfolders won’t create sub-sub folders unless I manually create the list. Here is the script…
This code fails
tell application “Finder”
set myTemp to my Verify_Backup_Path(“OSX Local HD:Test 1:Test 2:Test 3:tb2pro900.exe copy” as alias, “OS9 Local HD”)
end tell
– Will verify or create a duplicate folder structure from the source path
– To a destination location
on Verify_Backup_Path(Source_Path, Destination_Volume)
local Old_Delimiters
local Source_Folder_List
local Destination_Path
local i
local Destination
tell application "Finder"
--Set list to contain volume and every folder name in path. Final item is file name
set Old_Delimiters to AppleScript's text item delimiters
set AppleScript's text item delimiters to ":"
set Source_Folder_List to every text item of (Source_Path as string) -- Fills list with {"Volume Name", "Folder1 Name",..., "FolderX Name", "File Name"}
set AppleScript's text item delimiters to Old_Delimiters
set Source_Folder_List to items 2 thru -2 of Source_Folder_List -- Remove first item (volume) and last (file name)
--set Source_Folder_List to {"Test 1", "Test 2", "Test 3"}
-- Verify destination has same folder structure as source. If not make necessary folders
set Destination_Path to Destination_Volume
repeat with i from 1 to count of items in Source_Folder_List
try
make new folder at Destination_Path with properties {name:item i of Source_Folder_List}
end try
set Destination_Path to (Destination_Path & ":" & item i of Source_Folder_List) as string -- Add to path for next check
end repeat
--return (Destination)
end tell
end Verify_Backup_Path
Here is the event log.
tell application “Finder”
make new folder at “OS9 Local HD” with properties {name:“Test 1”}
folder “Test 1” of disk “OS9 Local HD”
make new folder at “OS9 Local HD:Test 1” with properties {name:“Test 2”}
make new folder at “OS9 Local HD:Test 1:Test 2” with properties {name:“Test 3”}
end tell
If I remove the comment from the line…
–set Source_Folder_List to {“Test 1”, “Test 2”, “Test 3”}
it works. (Here is its event log).
tell application “Finder”
make new folder at “OS9 Local HD” with properties {name:“Test 1”}
folder “Test 1” of disk “OS9 Local HD”
make new folder at “OS9 Local HD:Test 1” with properties {name:“Test 2”}
folder “Test 2” of folder “Test 1” of disk “OS9 Local HD”
make new folder at “OS9 Local HD:Test 1:Test 2” with properties {name:“Test 3”}
folder “Test 3” of folder “Test 2” of folder “Test 1” of disk “OS9 Local HD”
end tell
I have looked at the properties, tried different methods of creating the list. The only common item is manually creating the list is all that I have gotten to work.
What am I missing?