Forums > MaxMSP

Check if a certain file exists

November 7, 2012 | 11:20 am

I spend some time browsing through all the file-related objects and I can’t find any solution for my simple task:

before my patch opens a .xml file at startup (which contains some user default settings), it should check whether the file exists. Is there a quick way to accomplish this?

Thanks in advance


November 7, 2012 | 11:38 am

Here is a way:

http://cycling74.com/toolbox/mxj-filesys-v0-2-3/
but it’s also possible to do this in pure Max (it’s more fun to compute).

p


November 7, 2012 | 1:08 pm

Here’s a simple Javascript approach that I use.

– Pasted Max Patch, click to expand. –

November 7, 2012 | 1:44 pm

there is no need of java or javascript.

plain max version:

– Pasted Max Patch, click to expand. –

November 7, 2012 | 1:58 pm

Cool — I never thought about that one. Glad you mentioned it — I suppose the only benefit of my version is that it’s just one object instead of four but putting it in an abstraction addresses that.

I’m curious however as to why you used trigger objects rather than just messages containing 0 and 1 respectively?
E.g.,

– Pasted Max Patch, click to expand. –

November 7, 2012 | 2:16 pm

1) for backwards compatibility

2) less cpu usage.
a message box is an interface object, trigger object not.
not much in this case, but if you have many of them, it will affect performance.


November 7, 2012 | 2:18 pm

> why you used trigger objects

Maybe it’s a matter of style; I do it too. Then again, I remember a case in which I didn’t anticipate the message object receiving a set message, breaking functionality. With a trigger it is completely unambiguous.

@dupecom nice indeed


November 7, 2012 | 2:22 pm

@dupecom
Thanks for the explanation — I have a lot of message objects in my patchers for such things. Sounds like it will be worth my while to replace them with triggers…particularly where I’m dealing with incoming highspeed OSC messages.


November 7, 2012 | 2:24 pm

btw.
its not my solution. copied from 11olsen. thanx !!
he posted it here:

http://cycling74.com/forums/topic.php?id=38141


November 7, 2012 | 2:30 pm

It doesn’t matter if it’s not your solution — the value of teaching is not about originality.


April 17, 2014 | 4:27 pm

The problem with the [absolutepath] object is that searches everywhere on the hard drive – not just a specific folder – would there be a way to search for the file only in the selected folder?


April 19, 2014 | 2:23 pm

@dupecom really no need to give me credits for this kind of things. i for myself may have learned this detail about [absolutepath] on the forums.
@drkoss if you feed it an already absolute path it will just check if the file/folder is there and not search anywhere else on the disk. O.


April 19, 2014 | 4:42 pm

no wait, you’re right. it will match with other files with the same name in the max search path if the file is not found. just noticed it with a dict loading a file that wasn’t in that path.
you can get around that if you compare in and output path. the file only exist in exactly that path if input == output. like that:

– Pasted Max Patch, click to expand. –

i don’t know if i like that behaviour with other objects.
A dict, in this case, is loading even if the file doesn’t exist because the file is present somewhere else in the search path. that would be ok for relative filenames, but I’m sendind the abs. path with the "read message".


Viewing 13 posts - 1 through 13 (of 13 total)