Re: Where is the Missing Link?.
Re: Where is the Missing Link?.
- Subject: Re: Where is the Missing Link?.
- From: Paul Skinner <email@hidden>
- Date: Tue, 25 Sep 2001 13:13:08 -0400
That horse still ain't dead!
This will return the results sorted so that directories are grouped as
folder-then-files. This is probably more like the results that you were
wanting.
By the way if you have difficulty opening the resulting file you can use
many third party text apps that can handle the large size. But if you
haven't gotten it yet, bbedit lite is free and mighty fine.
http://www.barebones.com/products/bbedit_lite/lite-download.html
--begin script
set AppleScript's text item delimiters to return
set folderToStartAt to choose folder with prompt "Choose a folder to list
the contents of."
theEntireContentsOf(folderToStartAt)
set theData to the result
----------
tell application "Finder"
set folderName to name of folderToStartAt
if length of folderName is less than 22 then
set outputFileName to folderName & " contents"
else
if length of folderName is less than 31 then
set outputFileName to folderName
else
set outputFileName to characters 1 thru 31 of folderName
end if
end if
end tell
----------Write the data to the output file.
try
set toFile to ((path to desktop folder) as text) & outputFileName
try --ensure the file is not already open.
close access file toFile
end try
set target to open for access file toFile with write permission
write (asciisort((everyFolder of theData & everyFile of theData)) as
text) to target
close access target
on error errorMessage
return errorMessage
end try
set AppleScript's text item delimiters to ""
on theEntireContentsOf(sourcefolder)
set folderList to {}
set fileList to {}
----------
tell application "Finder"
try
copy ((every folder of the sourcefolder) as alias list) to
folderList
on error --1 item cannot be returned as 'alias list'. Known Finder
bug.
copy (((every folder of the sourcefolder) as alias) as list) to
folderList
end try
try
copy ((every file of the sourcefolder) as alias list) to
fileList
on error --1 item cannot be returned as 'alias list'. Known Finder
bug.
copy (((every file of the sourcefolder) as alias) as list) to
fileList
end try
end tell
----------
set theIndex to 1
repeat
try
set thisItem to item theIndex of folderList
tell application "Finder"
try
set folderList to folderList & ((every folder of
thisItem) as alias list)
on error --1 item cannot be returned as 'alias list'. Known
Finder bug.
set folderList to folderList & (((every folder of
thisItem) as alias) as list)
end try
try
set fileList to fileList & ((every file of thisItem) as
alias list)
on error --1 item cannot be returned as 'alias list'. Known
Finder bug.
set fileList to fileList & (((every file of thisItem) as
alias) as list)
end try
end tell
set theIndex to theIndex + 1
on error
exit repeat
end try
end repeat
----------
return {everyFolder:folderList, everyFile:fileList}
end theEntireContentsOf
on asciisort(parameters)
----------
-->>DESCRIPTION:<<--Define the function for handlerInfo return or error
handling.
set thisHandlerName to "thisHandlerName"
set handlerDescription to "Sorts lists by ASCII value."
set handlerRequiredParameters to "A list containing ASCII values."
set handlerOptionalParameters to "none"
set handlerReturns to "A new list sorted by ASCII values."
set handlerExample to "asciisort({7, 4, 6, 2, 5, 3, 0, 1, 5, 9, 8})
"
set handlerInfo to {thisHandlerName:thisHandlerName,
handlerDescription:handlerDescription,
handlerRequiredParameters:handlerRequiredParameters,
handlerOptionalParameters:handlerOptionalParameters,
handlerReturns:handlerReturns, handlerExample:handlerExample}
if parameters is missing value then --Return the handlers information to
the user.
return handlerInfo
end if
----------
-->> PARAMETER variable assignments:<<
if length of parameters = 3 and class of (item 1 of parameters) is list
then
set theList to item 1 of parameters
set startPoint to item 2 of parameters
set endPoint to item 3 of parameters
else
try
set theList to parameters as list
set startPoint to 1
set endPoint to length of theList
on error
return {handlerError:"Missing Parameter."} & handlerInfo
end try
end if
----------
-->>BODY:<<
try --Handle any errors not handled in the BODY code.
if length of theList > 1 then
set ascendingPointer to startPoint
set descendingPointer to endPoint
set middleItem to item ((startPoint + endPoint) div 2) of
theList
----------------------------------------------------------------------------
------------------------
repeat until descendingPointer is less than or equal to
ascendingPointer
repeat while item ascendingPointer of theList as string <
middleItem
set ascendingPointer to ascendingPointer + 1
end repeat
repeat while item descendingPointer of theList as string >
middleItem
set descendingPointer to descendingPointer - 1
end repeat
if ascendingPointer is less than or equal to
descendingPointer then
set {item descendingPointer of theList, item
ascendingPointer of theList} to {item ascendingPointer of theList, item
descendingPointer of theList}
set ascendingPointer to ascendingPointer + 1
set descendingPointer to descendingPointer - 1
end if
----------------------------------------------------------------------------
------------------------
end repeat
----------------------------------------------------------------------------
------------------------
if startPoint < descendingPointer then asciisort({theList,
startPoint, descendingPointer})
if endPoint > ascendingPointer then asciisort({theList,
ascendingPointer, endPoint})
----------------------------------------------------------------------------
------------------------
end if
set theResults to theList --Define the results.
on error errorMessage number errorNumber partial result errorResult from
errorFrom to ErrorTo --Handle any errors not handled in the BODY code.
end try
-->>RETURN the results of the handler.<<
return theResults
end asciisort
--end script
--
Paul Skinner