Find files if criteria contains in files

Hi,
I can’t get this piece of script working in AppleScript Studio, it works in AppleScript though. It searches for file containing the name “test”

set theFolder to ":path:to:folder:" as alias
		tell application "Finder"
			items of theFolder whose name contains "test"
		end tell

I prefer using shell commands in my script like this :

do shell script "find /path/to/folder -name test" 

but it only finds names that are test and not for example thisistest.jpg. If this can be achieved with shell scripts, then it would be more useful to me but if it can’t then I’ll go with the script above.

Thanks

Hi,

just use wildcards, that’s the equivalent to contains


do shell script "find /path/to/folder -name '*test*'"

Thanks, I’ve first googled a bit about the find command but couldn’t find what I was looking for so I posted it here.

Greetings from Belgium!

Just take a look at the find man page

-name pattern
True if the last component of the pathname being examined matches
pattern. Special shell pattern matching characters (['', ]‘’, *'', and ?‘’) may be used as part of pattern. These
characters may be matched explicitly by escaping them with a
backslash (``'').

I read that too but this confused me,

True if the last component of the pathname being examined matches
pattern.

It’s quite easy:
the default behavior of find is to check the whole path.
The last path component of a path is the name of the file or folder

Ah, thanks, now I understand :slight_smile:
I’m not that kind of guy that uses UNIX all the time but I like it in my applescripts somehow…