Re: Files to Text-file
Re: Files to Text-file
- Subject: Re: Files to Text-file
- From: "Marc K. Myers" <email@hidden>
- Date: Tue, 30 Oct 2001 01:57:56 -0500
- Organization: [very little]
>
Date: Mon, 29 Oct 2001 21:39:45 -0600
>
Subject: Files to Text-file
>
From: Scott Earleywine <email@hidden>
>
To: Apple AppleScript List <email@hidden>
>
>
I'm undoubtedly sure this has been answered before, but I have a bunch of
>
nested files that I was wanting to create a BBEdit text file.
>
>
For example...I might have the five files (shown below) nested all over the
>
place inside one main folder...the text file would contain all the files in
>
alphabetically order (as shown below):
>
>
01_file.xls
>
Beavis_Butthead.mp3
>
Cleatus.fcf
>
Mort.fst
>
Wilbur.doc
>
>
I would like this script to be a droplet...that is, just drop the 'highest'
>
folder onto it, and the script would navigate all the folders and find all
>
the
>
files and create the text file.
>
>
I know who to get the BBEdit stuff, but I need help getting the script to
>
navigate the nested folders and 'negotiate' all the files into a list to
>
print
>
to the resulting text file.
>
>
I have plenty of RAM, so that should not be a problem (if the script needs
>
to
>
get bloated while it runs).
This script does what you want but it doesn't use BBEdit. AppleScript
is quite capable of generating a text file using its own scripting
additions. Please watch out for line wraps and note that "[optn-L]"
stands in for the AppleScript continuation character. The script uses
the Akua Sweets scripting addition to extract the files from the nested
folders and to sort the list of names.
on run
open ({choose folder with prompt "Pick a folder to process:"})
end run
on open (itemList)
set {od, AppleScript's text item delimiters} to [optn-L]
{AppleScript's text item delimiters, {":"}}
set fileList to {}
repeat with anItem in itemList
if (anItem as text) ends with ":" then
set fileList to fileList & (the entries in (anItem as alias) [optn-L]
whose kinds are file [optn-L]
to a depth of -1)
else
set fileList to fileList & text item -1 of (text items of
(anItem as text))
end if
end repeat
repeat with anItem in fileList
set contents of anItem to text item -1 of contents of anItem
end repeat
set fileList to order list fileList
set AppleScript's text item delimiters to {return}
set fileList to fileList as text
set AppleScript's text item delimiters to od
set fileName to (path to desktop as text) & "File List"
set fileID to (open for access file fileName with write permission)
try
set eof fileID to 0
write fileList to fileID starting at eof
close access fileID
on error m number n
try
close access fileID
end try
display dialog "Error Number " & (n as text) & return & m
end try
end open
Marc K. Myers <email@hidden>
http://AppleScriptsToGo.com
4020 W.220th St.
Fairview Park, OH 44126
(440) 331-1074
[10/30/01 1:54:21 AM]