Re: How to speed up execution time of this script
Re: How to speed up execution time of this script
- Subject: Re: How to speed up execution time of this script
- From: Rainer Standke <email@hidden>
- Date: Sat, 14 Aug 2010 20:10:16 -0700
Not to pre-empt Mark, but you might want to look into getting familiar with some Unix commands there is grep which let's you perform regular expression searches, and sed was mentioned, which I believe stands for stream editor. The list of files in subfolders can be had with ls.
You can use 'do shell script' from AppleScript, but it might be easier to explore it from Terminal. In Terminal you can do things like type 'man ls' to see the manual for the ls command, and you can figure out how to list files in a folder recursively. (You can also Google man ls.)
While you're looking into Unix, the pipe-character '|' pipes the output, or result, from one command into the input of another.
This just scratches the surface, I'm afraid, but it might help you to get going.
Rainer Standke
XMiL Workflow Tools
http://www.xmil.biz
On Aug 14, 2010, at 15:11 , Bert Groeneveld wrote:
> Hello Mark,
> Many, many thanks for your help.
>
> You're of course right there may exist more files with the same name in different subfolders. Initially, before I knew this was all possible, I figured out the quickest way was getting a list with only filenames and then restoring the full path by looping through all the subfolders with an "if exists" Finder script. Anyway:
>
> 1) That "pattern" search you use, is that the same as the so called "grep" searching? I once learned something about that in the TextWrangler user manual (Chapter 8 - Searching with Grep). I'm afraid the TextWrangler patterns are not the same as the patterns you use?
> As an exercise I tried this without succes: I want to find all the files in a folder whose file name starts with at least 20 characters or digits (except spaces) followed by the articlenumber. I called the handler with the namePattern argument "[^ ]{20}" & articleNumber & "*" As said without succes. No wonder likely, since this is a TextWrangler pattern.
> Here's what I actually want: I want to get a list (full paths) of all the files in a certain folder (including those files in subfolders) whose file name (including the extension) contains one or more contiguous substrings of 20 characters or digits without spaces and dashes. Is that possible?
> Examples:
> Will be included: "thisisaverylongfilename.jpg", "this isaveryverylongfilename 123.jpg" , "this isavery_verylong_file_name 123.jpg"
> Not to be included: "this is avery long filename.jpg", "this-is-avery-long-filename.jpg"
>
> 2) I really would like to know in plain english ;) what you're telling here: | sed -e 's,.*/,,' "
>
> 3) Is it also possible to return the paths as Applescript references instead of posix paths?
> If not: Is this the smartest way to convert a posix path into an Applescript file reference?
> set myResult to "/Applescript/Giving/SpreadTool/HiRes_Images/3148333_G.psd" as POSIX file as string
>
> Thanks again for your your kind help.
>
> Bert.
>
>
>
> On 14 aug 2010, at 00:04, Mark J. Reed wrote:
>
>> On Fri, Aug 13, 2010 at 5:30 PM, Bert Groeneveld
>> <email@hidden> wrote:
>>> Note: I also need the names of the files in all the subfolders (entire
>>> contents).
>>
>> I'm a bit confused - doesn't "name of" a file return just the name,
>> without the path? So if you have two of the same filename in two
>> different subfolders, you can't tell them apart? I guess your problem
>> domain is such that that never happens?
>>
>> Anyway, there are ways to do that from shell, sure. Consider this handler:
>>
>> to findMatchingFiles(parentFolder, namePattern)
>> return paragraphs of (do shell script ¬
>> "find " & (quoted form of POSIX path of parentFolder) ¬
>> & " -name " & (quoted form of namePattern) & " -print")
>> end
>>
>> The above returns the full POSIX paths of each file; if you just want
>> the base filenames, you can do this instead:
>>
>> to findMatchingFileNames(parentFolder, namePattern)
>> return paragraphs of (do shell script ¬
>> "find " & (quoted form of POSIX path of parentFolder) ¬
>> & " -name " & (quoted form of namePattern) & " -print | sed -e
>> 's,.*/,,' ")
>> end
>>
>> Given those handlers, you can translate your examples thus:
>>
>>> set all_the_Hires_Images to name of every file of entire contents of
>>> the_ImagePath_folder whose name begins with articleNumber
>>
>> findMatchingFileNames(the_ImagePath_folder, articleNumber & "*")
>>
>>
>>> set all_the_Hires_Images to name of every file of entire contents of
>>> the_ImagePath_folder whose name contains ("." & articleNumber)
>>
>> findMatchingFileNames(the_ImagePath_folder, "*." & articleNumber & "*")
>>
>> The name patterns are simple wildcards: "foo*" matches anything that
>> starts with "foo", "*foo" matches anything that ends with "foo", and
>> "*foo*" matches anything that contains "foo". They're not full regular
>> expressions; you can get a little fancier, but you don't need to in
>> this case.
>>
>>> Bert.
>>> On 9 aug 2010, at 19:28, Mark J. Reed wrote:
>>>
>>> On Mon, Aug 9, 2010 at 8:10 AM, Bert Groeneveld
>>> <email@hidden> wrote:
>>>
>>> set all_the_Hires_Images to name of every file of the_ImagePath_folder
>>>
>>> Why not filter it at this point... as I see Ed has suggested:
>>>
>>> set foundImageNames to every file of the_ImagePath_folder whose name
>>> begins with articleNumber
>>>
>>> But you can probably do much better with the shell:
>>>
>>> set foundImageNames to paragraphs of (do shell script "cd " & quoted
>>> form of posix path of the_ImagePath_folder & " && ls -1 " &
>>> articleNumber & "*")
>>>
>>> Note that all the solutions so far will, for instance, find "654" if
>>> you ask for "65". If there's any sort of delimiter between the
>>> article number and the rest of the filename, you should include that
>>> at the end of the pattern you search for.
>>>
>>> --
>>> Mark J. Reed <email@hidden>
>>>
>>>
>>>
>>>
>>
>>
>>
>> --
>> Mark J. Reed <email@hidden>
>>
>>
>
>
> _______________________________________________
> 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
_______________________________________________
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