Re: Find out in which subfolder a given file resides
Re: Find out in which subfolder a given file resides
- Subject: Re: Find out in which subfolder a given file resides
- From: Axel Luttgens <email@hidden>
- Date: Wed, 14 Oct 2015 12:11:43 +0200
> Le 14 oct. 2015 à 11:23, Bert Groeneveld a écrit :
>
> […]
>
> Hi Axel, I would say, yes.
So, the basic idea would be to execute:
find '/Volumes/SP/HR_Images' -type f \( -name 'p1.jpg' -or -name 'p2.jpg' \)
for finding regular files ("-type f") named "p1.jpg" or "p2.jpg" in the same invocation of find.
A sample basic handler:
on findFiles(folderPath, fileNames)
local TIDs, cmd
set folderPath to quoted form of folderPath
repeat with i from 1 to count of fileNames
set item i of fileNames to "-name " & quoted form of item i of fileNames
end repeat
set TIDs to AppleScript's text item delimiters
set AppleScript's text item delimiters to {" -or "}
set fileNames to fileNames as text
set AppleScript's text item delimiters to TIDs
set cmd to "/usr/bin/find " & folderPath & " -type f \\( " & fileNames & " \\)"
return paragraphs of (do shell script cmd)
end findFiles
Applying it to above example:
findFiles("/Volumes/SP/HR_Images", {"p1.jpg", "p2.jpg"})
it should return a list of the posix paths of found files, eg:
{"/Volumes/SP/HR_Images/A/p1.jpg", "/Volumes/SP/HR_Images/X/p2.jpg"}
There is at least one caveat: this supposes you’ll never have to handle files with a carriage return or a linefeed character in their name (that restriction could be leveraged, but with some additional complexity).
Could you try it for real?
Unless I’m wrong, the most costly operations are the file system accesses, the name parsing being quite marginal in comparison (provided there are no thousands and thousands of file names to handle, of course…).
> To find all the images at once, do all the names need to be available in a single list? That is not the case at the moment.
That’s indeed what I supposed in the above, since lists are a "natural" way to handle collections in AppleScript. But clearly, this is not imperative.
HTH,
Axel
_______________________________________________
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