Re: Path-Strings to Formatted String
Re: Path-Strings to Formatted String
- Subject: Re: Path-Strings to Formatted String
- From: Jason Bourque <email@hidden>
- Date: Fri, 15 Feb 2002 19:57:21 -0500
Arthur,
I wrote this a while ago, and I don't remember if I sorted the folders but
it should do what you need.
I called it Folder Heirarchy Mapper
It writes a text file of the heirarchy.
Save it as a droplet and drop a folder onto it.
Jason Bourque
Co-Director Boston AppleScript User Group
-- the list of file types which will be processed
property typeList : {}
property folderMapFile : ""
property depthCounter : 1
property foldercounter : 0
-- This droplet processes both files or folders of files dropped onto the
applet
on open theseItems
--set theseItems to {alias "Macintosh HD:Desktop Folder:Test html
folder:"}
set folderMapFile to ""
set depthCounter to 1
set foldercounter to 0
tell application "Finder"
set myLocation to (container of (item 1 of theseItems)) as string
set topFolderName to name of item 1 of theseItems
set folderMapFile to myLocation & topFolderName & ".map"
end tell
try
open for access file folderMapFile with write permission
repeat with i from 1 to the count of theseItems
set thisItem to (item i of theseItems)
set the itemInfo to info for thisItem
if folder of the itemInfo is true then
write topFolderName & return & return to file folderMapFile
starting at eof
processFolder(thisItem as string)
end if
end repeat
on error
close access file folderMapFile
end try
try
close access file folderMapFile
end try
delay 2
tell application "Finder"
select file folderMapFile
open file folderMapFile
end tell
end open
-- this sub-routine processes folders
on processFolder(thisFolder)
tell application "Finder"
try
set theseItems to name of every folder of folder thisFolder as
list
on error
set theseItems to {}
end try
set foldercounter to count of theseItems
end tell
my ASCIISort(theseItems)
set theseItems to result
repeat with nth from 1 to foldercounter
set thisItem to ((thisFolder as string) & (item nth of theseItems))
repeat (depthCounter * 8) times
write tab to file folderMapFile starting at eof
end repeat
write (item nth of theseItems) & return to file folderMapFile
starting at eof
set depthCounter to depthCounter + 1
processFolder(thisItem & ":")
end repeat
set depthCounter to depthCounter - 1
if depthCounter is 2 then
write return to file folderMapFile starting at eof
end if
end processFolder
on ASCIISort(myList)
set the indexList to {}
set the sortedList to {}
repeat (the number of items in myList) times
set the lowItem to ""
repeat with i from 1 to (number of items in myList)
if i is not in the indexList then
set thisItem to item i of myList as text
if the lowItem is "" then
set the lowItem to thisItem
set the lowItemIndex to i
else if thisItem comes before the lowItem then
set the lowItem to thisItem
set the lowItemIndex to i
end if
end if
end repeat
set the end of sortedList to the lowItem
set the end of the indexList to the lowItemIndex
end repeat
return the sortedList
end ASCIISort
On 2/15/02 1:44 PM, "Arthur J Knapp" <email@hidden> wrote:
>
OK, my brain is beginning to hurt, perhaps someone could do all my
>
work for me so I can go home? ;-)
>
>
>
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:
>
"
>
>
where each indentation level is preceeded by an appropriate
>
number of tabs.
>
>
After several hours of playing with this, I've come to
>
realize that it is a lot harder than it looks to accomplish
>
this, as it seems to require several nested repeat loops
>
and a lot of maintaining of "state", or really complex
>
recursion that I just can't seem to work out the details of.
>
>
>
Thanks in advance. :)
>
>
>
{ Arthur J. Knapp, of <http://www.STELLARViSIONs.com>
>
<mailto:email@hidden>
>
try
>
<http://www.seanet.com/~jonpugh/>
>
on error number -128
>
end try
>
}
>
_______________________________________________
>
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.
_______________________________________________
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.