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 11:51:22 -0400
on 9/25/01 10:32 AM, Rachel Cogent wrote:
>
Last by 2 AM I finally became frustrated to tears at how to do this most
>
rudimentary operation in AppleScript Which 2 days ago I described in DOS
>
batch terms:
>
DIR/s>textfile
>
This command makes a directory list of all files and all files in all
>
subdirectories and writes the output to "textfile".
>
>
I must have wasted 16 hours in the last few days trying to do this
>
operation.
>
There must be a way to do this in simple AppleScript, please don't recommend
>
I buy Script debugger, I am on social security and have hardly any money.
>
Yesterday after reading the praises of AppleScript I was willing to forgive
>
and forget, but now I am as disgusted as ever. This is not even a request
>
for help, just an expression of my failure to understand the rules of this
>
most difficult of languages. Besides wanting to actually get something done,
>
I am struggling to learn this stuff and failing miserably.
>
Today I will download this ASLG, maybe that is the missing link.
>
>
Rachel http://www.gnarlodious.com
Sorry to hear about your frustration. I do think that the ASLG will help
fill in many of the missing pieces, but you will probably still encounter
the occasional brick wall. Come back here when you do. Some people here have
ladders.
Ahhh...DIR/s>textfile. It's been years since I saw that. I still have a
IBM PC jr in my closet!
I think this may do what you want without adding any OSAX to your
system. Not that that would be a bad thing. This will be slow if you do a
very large hierarchy (Like your entire HD) an OSAX like AKUA is a much
faster solution but for many folders this will be very quick. Save it as an
App and give it a lot of memory if it fails with out-of-memory errors.
If any line in the following script suddenly stops following the
indentation of it's predecesor, it has been wrapped by the listserver. Just
edit out the return on the previous line.
--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."
set theData to theEntireContentsOf(folderToStartAt)
----------Name the output file appropriately.
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 ((everyFolder of theData as text) & everyFile of theData as text)
to target --as text
close access target
on error errorMessage
return errorMessage
end try
set AppleScript's text item delimiters to ""
on theEntireContentsOf(the 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
--end script
--
Paul Skinner