Re: Path-Strings to Formatted String: Refined
Re: Path-Strings to Formatted String: Refined
- Subject: Re: Path-Strings to Formatted String: Refined
- From: Jason Bourque <email@hidden>
- Date: Sun, 17 Feb 2002 11:12:17 -0500
I refined it a little bit and turned it into a hander.
Nice one to have.
Thanks for asking the question, I see many ways I could use this.
Jason Bourque
Co-Director Boston AppleScript Users Group
set lFolderList to {,
"MacHD2:Projects:Project 2:Old:CHAP01:", ,
"MacHD:Projects:Project 1:Art:CHAP01:", ,
"MacHD:Projects:Project 1:Art:CHAP02:", ,
"MacHD:Projects:Project 2:Art:CHAP01:File Name", ,
"MacHD:Projects:Project 2:Art:CHAP02:", ,
"MacHD:Projects:Project 2:Old:CHAP01:", ,
"MacHD:Projects:Project 2:Old:CHAP01:Page 1:", ,
"MacHD:Projects:Project 2:Old:CHAP02:"}
tell me to srDirectoryMapper(lFolderList, tab & "|", ":")
on srDirectoryMapper(lFolderList, lIndent, lFolderIndicator)
-- Ensure that the list was sorted.
-- tell me srListSort(lFolderList)
-- set lFolderList to result
-- Capture the current delimiter for AppleScript at the beginning of the
handler
set {lTids, AppleScript's text item delimiters} to {AppleScript's text
item delimiters, ""}
-- Temp variables
set {lDirectoryList, lIndentList, lPreviousFolderPathList} to {{}, {},
{}}
repeat with lNth from 1 to count of lFolderList
set AppleScript's text item delimiters to ":"
-- Separate the path into folders.
set lFolderPathItemsList to text items of item lNth of lFolderList
set AppleScript's text item delimiters to ""
repeat with lNth2 from 1 to ((count of lFolderPathItemsList) - 1)
set lFolderName to item lNth2 of lFolderPathItemsList
try
set lLastFolderName to item lNth2 of lPreviousFolderPathList
on error
set lLastFolderName to ""
end try
-- Build the indention.
if lNth2 is greater than 1 then set lIndentList to lIndentList &
lIndent
-- Capture the folder.
if lFolderName is not lLastFolderName then copy ((lIndentList as
text) & lFolderName) to end of lDirectoryList
end repeat
-- Reset the temp variables
set {lIndentList, lPreviousFolderPathList} to {{}, {}}
-- Get the next comparison path.
copy lFolderPathItemsList to lPreviousFolderPathList
end repeat
-- Separate the lines of text with a folder indicator and a paragraph
return.
set AppleScript's text item delimiters to lFolderIndicator & return
-- Collapse the list to a string.
set lDirectoryMap to lDirectoryList as text
-- Reset the delimiter for AppleScript to its previous call state
set AppleScript's text item delimiters to lTids
return lDirectoryMap
end srDirectoryMapper
_______________________________________________
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.