• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: How to speed up execution time of this script
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to speed up execution time of this script


  • Subject: Re: How to speed up execution time of this script
  • From: Bert Groeneveld <email@hidden>
  • Date: Sun, 15 Aug 2010 00:11:08 +0200

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
  • Follow-Ups:
    • Re: How to speed up execution time of this script
      • From: "Mark J. Reed" <email@hidden>
    • Re: How to speed up execution time of this script
      • From: Rainer Standke <email@hidden>
References: 
 >How to speed up execution time of this script (From: Bert Groeneveld <email@hidden>)
 >Re: How to speed up execution time of this script (From: "Mark J. Reed" <email@hidden>)
 >Re: How to speed up execution time of this script (From: Bert Groeneveld <email@hidden>)
 >Re: How to speed up execution time of this script (From: "Mark J. Reed" <email@hidden>)

  • Prev by Date: Re: What's in an iCal url?
  • Next by Date: Re: How to speed up execution time of this script
  • Previous by thread: Re: How to speed up execution time of this script
  • Next by thread: Re: How to speed up execution time of this script
  • Index(es):
    • Date
    • Thread