I need to get all the files in a folder whose name contains a certain word. I start with something ike this:
set x to (do shell script yyy)
Little help please.
I need to get all the files in a folder whose name contains a certain word. I start with something ike this:
set x to (do shell script yyy)
Little help please.
Hi.Change “whatever” to the target word.
set foundItems to (do shell script "find " & my (choose folder)'s POSIX path's quoted form & " -name '*whatever*' ")'s paragraphs
I tested Marc’s suggestion and it works great. Just FWIW, the OP should be aware that the script returns hidden files, files in packages, and directories (which can be avoided with -type f).
here is what I have in the editor.
set search_folder to “Macintosh HD:Users:shawnbrady:Dropbox:Audio:Features:SAL350 Ruiz, Luis NPR:Audio”
set foundItems to (do shell script "find " & my search_folder’s POSIX path’s quoted form & " -name ‘main’ ")'s paragraphs
nothing is found.
You removed the * from around the search string–take another look at Marc’s suggestion.
Another shell-script approach that works, provided the script does not have to act recursively:
set theFolder to quoted form of POSIX path of (choose folder)
set theString to "aaa"
set theFiles to paragraphs of (do shell script "ls " & theFolder & "*" & theString & "*")