[Closed] Checking strings in a file name
I understand how to check for names of objects, but how do you check a filename for certain strings?
Ex
filename = "c://This//is//my//file//myfile.max"
if (filename ?contains? "Monkey" or filename ?=? "*Monkey*") then
(
print ("poop")
)
I tried the == “name” but it didn’t fly. Also has anyone had trouble with their max 8 help file? For some reason some sections of my help file are showing up as broken.
Thanks for any help on this.
Don’t use “//”. Either use “\” or “/”.
You can use matchPattern which is MUCH faster than findstring().
For example,
if matchPattern filename pattern:"*monkey*" then print "Poop"
You can also filter out the backslashes and turn the filename into an array, then compare the sub-folder names with your search string.
theFString = filterString filename "/\\"
if findItem theFString "monkey" > 0 then print "Poop" --this assumes you are searching for a sub-folder with EXACTLY that name
you don’t have to treat filenames any different then strings in this case
if what you’re trying to do is search for a string within a filename you need the “findstring”
if findstring filename "monkey" != undefined then print "poop"
Wohoo,
Both methods worked, but I ended up using matchpattern because I will be running over terabytes of information and want as much speed as possible. The findstring method is cool as well, and I am sure I iwll find a time when I will need to use it.
As always thank you very much for the assistance.
–Jon