Problem creating folders from list

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?

Since the log seems to indicate the syntax is correct, it seems likely that you’re running into the Finder’s cache problem - namely the Finder doesn’t recognise the fact the folder has been created yet.

The fix is to either add a delay to your script after creating a folder (this delay gives the Finder time to update its cache), alternatively force the Finder to update the cache by using the Finder’s ‘update’ command.

Pardon me while I grumble: I wish the damn OSX Finder would update itself more often. I hate using a machine that feels like its chips have molasses poured all over them.

Neither a delay or the update command worked. Currently I have the script running on 10.3.3 so I will try it on different versions of the OS to see if I get the same results.

It does work if I set the list myself rather than extracting folders from the file path.

set Source_Folder_List to {“Test 1”, “Test 2”, “Test 3”}

Hmm, well, although you’re running the script under OS X, you appear to be targeting an OS 9 volume, which makes me wonder if Unicode text might be a part of the problem. What does this return with your test folders?:


set Source_Folder_List to items 2 thru -2 of Source_Folder_List
return (Source_Folder_List equals {"Test 1", "Test 2", "Test 3"})

Ah. I see the admiral’s had the same thought. :slight_smile: The only diffference I can see between the derived and “manual” lists is that the strings in the former are Unicode text. (Alias-to-string coercions come out that way in Jaguar and, presumably, in Panther.)

I see the destination path refers to “OS 9 Local HD”. Is the script being run over a network to an OS 9 machine? The syntax:

make new folder at Destination_Path

… isn’t tolerated in OS 9 if Destination_Path is a Unicode string. I’m only guessing, but maybe it’ll help if you correct that line to:

make new folder at folder Destination_Path with properties {name:item i of Source_Folder_List}
-- or:
make new folder at alias Destination_Path with properties {name:item i of Source_Folder_List}

This returns true. (At first I thought it returned false but I have tried several more times (from the start) and it returns true. When I deleted the return statement, it did not create the second and third folder.

set Source_Folder_List to items 2 thru -2 of Source_Folder_List
return (Source_Folder_List is equal to {“Test 1”, “Test 2”, “Test 3”})

The “OS9 Local HD” is a local drive.

The intent of the script is to actually work over a network to and archive files from an incoming ftp folder. It will check 300+ folders and

  1. Mount server volume.

  2. In backup folder - purge all files over 3 months old and delete folders where last file was deleted.

  3. In original folder - If file is not labeled, modify the file to the current date and set the label (Used to indicate a new file independent of date)

  4. In original folder - If labeled and older than one week, mimic folder path from orig to backup and move file to backup.

  5. Dismount server volume.

Most everything is working except the mimic folder path. Everything has only been tested locally but only with a total of about 10 folders.

I think it is working now. I tried coercing the string as an alias then string. This seems to work.

set Destination_Path to (Destination_Volume as alias)
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 as string) & “:” & item i of Source_Folder_List) as alias – Add to path for next check
end repeat

Thanks for you assistance!!!