PDA

View Full Version : Checking strings in a file name


Jonbojangles
02-20-2006, 06:30 AM
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.

Aearon
02-20-2006, 07:54 AM
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"

Bobo
02-20-2006, 01:06 PM
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

Jonbojangles
02-21-2006, 05:00 PM
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

CGTalk Moderation
02-21-2006, 05:00 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.