Re: Path-Strings to Formatted String
Re: Path-Strings to Formatted String
- Subject: Re: Path-Strings to Formatted String
- From: Nigel Garvey <email@hidden>
- Date: Sat, 16 Feb 2002 03:54:39 +0000
Arthur J Knapp wrote on Fri, 15 Feb 2002 13:44:27 -0500:
>
OK, my brain is beginning to hurt,
You didn't put it in a record and try to coerce it to string, did you?
;-)
>
I have a list, (let's call it foldList), of folder path-strings:
>
>
{ "MacHD:Projects:Project 1:Art:CHAP01:",
>
"MacHD:Projects:Project 1:Art:CHAP02:",
>
"MacHD:Projects:Project 2:Art:CHAP01:",
>
"MacHD:Projects:Project 2:Art:CHAP02:",
>
"MacHD:Projects:Project 2:Old:CHAP01:",
>
"MacHD:Projects:Project 2:Old:CHAP02:" }
>
>
An important property of this list to mention is that my script
>
has previously sorted it, such that:
>
>
( foldList's item x < foldList's item (x + 1) ) = true
>
>
What I want to achive is a string in this format:
>
>
"MacHD:
>
Projects:
>
Project 1:
>
Art:
>
CHAP01:
>
CHAP02:
>
Project 2:
>
Art:
>
CHAP01:
>
CHAP02:
>
Old:
>
CHAP01:
>
CHAP02:
>
"
This isn't elegant, but it'll get you there - assuming you had to start
from here....
-- The indexing scheme requires two more tabs than are actually used
property kTabStr : tab & tab & tab & tab & tab & tab
property kLineEnd : ":" & return
-- ;-)
set foldList to {"MacHD:Projects:Project 1:Art:CHAP01:", ,
"MacHD:Projects:Project 1:Art:CHAP02:", ,
"MacHD:Projects:Project 2:Art:CHAP01:", ,
"MacHD:Projects:Project 2:Art:CHAP02:", ,
"MacHD:Projects:Project 2:Old:CHAP01:", ,
"MacHD:Projects:Project 2:Old:CHAP02:"}
set AppleScript's text item delimiters to {":"}
-- Use the disk name to initialise a parent-path-comparison string
set parentPath to foldList's first item's first text item
-- Start the output with that (no tab)
set outList to {parentPath & kLineEnd}
-- Handle each path string in turn
repeat with thisPath in foldList
set i to -3 -- text item -3 is the penultimate folder name
-- Find out how much of the path to tab or reconstuct
repeat until thisPath's text 1 thru text item i is in parentPath
set i to i - 1
end repeat
-- Set a new parent-comparison if this has changed
if i < -3 then set parentPath to text 1 thru text item -3 of thisPath
-- Add the necessary items to the output
repeat with i from i to -3
set the end of outList to kTabStr's text 1 thru i & thisPath's text
item (i + 1) & kLineEnd
end repeat
end repeat
set AppleScript's text item delimiters to {""}
outList as string
NG
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.