Re: Get every file of the entire contents of a folder. Quickly.
Re: Get every file of the entire contents of a folder. Quickly.
- Subject: Re: Get every file of the entire contents of a folder. Quickly.
- From: Paul Skinner <email@hidden>
- Date: Tue, 14 Oct 2003 16:45:01 -0400
On Tuesday, October 14, 2003, at 11:07 AM, Paul Berkowitz wrote:
On 10/14/03 7:36 AM, "Paul Skinner" <email@hidden> wrote:
Unfortunately, there was a major bug in the code I wrote. Grep was
not the way to go for the containing search. I was getting hits where
the file path contained the search term. The 'find' shell command has
it's own switch for this. And the results are not only more accurate,
but they come back quicker!
It looks even better. But I must be missing something: you're still
doing
'as text' when it should be 'as Unicode text' since file- and folder-
paths
may well contain non-ASCII characters.
set folderReference to (parameters's item 1 as text) as alias
should be
set folderReference to (parameters's item 1 as Unicode text) as
alias
I didn't use it because I'm hard-headed, still think in my own
localization, and I don't use whacky characters in naming my folders or
files. In fact, It didn't occur to me, even after reading your post,
that an alias or path in AppleScript could contain Unicode characters.
Like I said, hardheaded.
In the future, I plan on using 'as Unicode text' on all occasions
where I have previously used 'as text'. Is there any downside to this
strategy?
In fact, the 'folderReference' is to (choose folder) in the example
you give, and 'choose folder's result is an alias to begin with.
Perhaps all this in case a Finder folder-reference is given instead?
yes.
In that case (or in any case) why not just 'as alias'? Why do you
need 'as text' or 'as Unicode text' at all, 'as alias' will work with
Finder, string or Unicode paths, or alias references? What am I
missing here? And if it does need first coercion to text, why not
Unicode text?
Fine question. It should be just 'as alias'.
And why this lower down:
set filelist to (DiskName & (filelist as text) as Unicode text)
Why not just:
set filelist to (DiskName & filelist) as Unicode text)
Why lose the Unicode in the paths before coercing it back? You'll lose
all the non-ASCII characters that way and will get errors if there are
any.
Since I already mentioned this (you didn't replay that time), and
you're still doing it, you must have a good reason I'm missing - maybe
some situation I haven't considered. Please tell. The method itself
looks terrific.
Unfortunately no. Your assessment is right on. It should be 'set
filelist to (DiskName & filelist) as Unicode text)', but I question if
that is even necessary since DiskName is already unicode. Doesn't the
first item determine type of subsequent appended strings?
--
Paul Berkowitz
So...
EveryFileOfFolder({choose folder, ".jpg"})
on EveryFileOfFolder(parameters)
set termExists to parameters's class is list
if termExists then
set folderReference to parameters's item 1 as alias
set searchterm to parameters's item 2
else
set folderReference to parameters as alias
end if
set folderPath to quoted form of (POSIX path of folderReference)
set shellFind to "find " & folderPath & " ! -name '\\.*' -type f | tr
-s '//' | tr '/' ':'"
if termExists then set shellFind to "find " & folderPath & " ! -name
'\\.*' -name '*" & searchterm & "*' -type f | tr -s '//' | tr '/' ':'"
try
set filelist to paragraphs of (do shell script shellFind)
on error
return {}
end try
set prevDelim to text item delimiters
set text item delimiters to ":"
set DiskName to return & text item 1 of (folderReference as Unicode
text)
set AppleScript's text item delimiters to DiskName
set filelist to (DiskName & filelist) as Unicode text
set filelist to (DiskName & (filelist as text) as Unicode text)
set AppleScript's text item delimiters to return
set filelist to paragraphs 2 thru -1 of filelist
set AppleScript's text item delimiters to prevDelim
return filelist
end EveryFileOfFolder
_______________________________________________
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.