Re: Finding Filenames that contain a certain string
Re: Finding Filenames that contain a certain string
- Subject: Re: Finding Filenames that contain a certain string
- From: "Stockly, Ed" <email@hidden>
- Date: Fri, 20 Jul 2007 13:27:06 -0700
- Thread-topic: Finding Filenames that contain a certain string
>> (Of course, all this goes way beyond the scope of what the original poster
was asking for)
> I don't think it does. The OP wanted to find all files within a given folder
whose names consisted of a given prefix, followed by any lowercase letter,
followed by anything else.
You're right, I just looked back at the OP's request. : )
Here, then, is a plain vanilla applescript solution:
set myFolder to choose folder
set filenames to {}
set fileNameRoot to "325010"
set lowerCaseLetters to every item of "abcdefghijklmnopqurstuvwxyz"
repeat with thisletter in lowerCaseLetters
set the end of filenames to fileNameRoot & thisletter
end repeat
choose from list filenames
tell application "Finder"
set allFoundFiles to {}
repeat with thisFileName in filenames
try
set foundFiles to (every file of myFolder whose name begins with
thisFileName)
if the class of foundFiles is not list then
set the end of allFoundFiles to foundFiles
else
set allFoundFiles to allFoundFiles & foundFiles
end if
end try
end repeat
return allFoundFiles
end tell
> I feel that a regex solution, where I can use the range notation [a-z], is
both simpler to construct and easier to read than a solution that requires
explicitly enumerating (either as a literal or via construction) a 26-element
list containing all the lowercase letters.
Of course, but, you are an accomplished shell scripter with more than 20
years experience in reading and writing shell scripting and only a few years
of appleScript experience, and that was probably mostly using do shell
script and not scripting a lot of applications. Certainly you'll be more
comfortable with shell scripting and shell scripting syntax.
And if you were posting shell script solutions in favor of appleScript
solutions on the mac script digest or a shell scripting list no one would
bat an eye.
But, again, this is the applescript users list.
And, again, this is the best, if not the only, source for new appleScripters
to get interactive support.
One reason people come to appleScript is because it's syntax makes it easy
to understand and learn.
I criticize the tendency to answer simple appleScript questions with
difficult to understand shell script solutions because they tend to
discourage those who want to learn appleScripting and are more comfortable
with an English like syntax. New users come away from this list thinking
appleScript requires a deep knowledge of shell scripting and that's
discouraging.
>>> I mean, in English, I can just say "the lowercase letters" and you know what
I mean. I don't have to say "Lowercase A or B or C
If your point is that there should be better, native, text handling commands
in appleScript, I agree wholeheartedly. There are third party apps and osax
that do a pretty good job of manipulating text.
> In an ideal world, the Finder would support regular expression matching on
filenames directly, and would have done so long before OS X.
In an ideal appleScript world, an appleScript variation regular
expressions would work:
Get Every file of myFolders whose name begins with a number followed by a
lower case letter and whose body contains {"AppleScript" ,"Rules"}
Regular expressions, is basically a language.
ES
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden