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>