Forums > MaxMSP

check to see if text file exists?

July 28, 2008 | 11:04 pm

hello,

how would i check to see if a text file exists?

i found a post in the javascript forum, but didnt seem like they had much success: http://www.cycling74.com/forums/index.php?t=msg&goto=137889&rid=0&S=b7cbea944e03f640251c16cc459299e1

ideally, i’d like to stay in max, rather than javascript… but i cant seem to find an object that will do this. either way any solution would be much appreciated!

thanks, j


July 29, 2008 | 12:40 am

much hackier and stoopider then some simple javascript, but…

– Pasted Max Patch, click to expand. –

July 29, 2008 | 3:08 am

On Jul 28, 2008, at 4:04 PM, justin wrote:
> how would i check to see if a text file exists?

Where do you want to check?

In the same folder as your patcher?

Any arbitrary location?

-C

Chris Muir
cbm@well.com

http://www.xfade.com


July 29, 2008 | 5:31 am

On Jul 28, 2008, at 4:04 PM, justin wrote:

> i cant seem to find an object that will do this. either way any
> solution would be much appreciated!

I threw together an example of how to query the existence of a file.
It’s called FileExists, and it’s on my examples page:

http://www.xfade.com/max/examples/

Chris Muir
cbm@well.com

http://www.xfade.com


July 29, 2008 | 6:25 am

this is a classic "no output is the answer" kind of problem.
the workaround for this is to provide a default result that gets
overwritten by an actual result.
when the process is done, query the state and you’ll always get an
answer.

stoopid but effective

/*j

– Pasted Max Patch, click to expand. –

July 29, 2008 | 6:36 am

and here’s a version that actually works:

/*j

– Pasted Max Patch, click to expand. –

July 29, 2008 | 8:40 am

thanks all, the filein solution seems best for my needs.

its funny that i was staring at filein for a while last night. i thought it would be a contender for this kind of work. but, by that time, i think my brain was fried after too much patching.

justin


July 29, 2008 | 9:27 am

weird, under max 4 the filein object responds differently – for a start it only outputs a bang from right outlet…

anyway i sorta hacked something that seems to work in v4 (based on the examples above):

justin

#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P comment 26 112 48 196617 init bang;
#P message 249 53 73 196617 read blah.text;
#P message 154 53 77 196617 read filein.help;
#P window linecount 2;
#P comment 261 85 176 196617 * only tests files in max searchpath , unless full path is specified!;
#P window linecount 1;
#P newex 25 188 64 196617 route filein:;
#P toggle 25 267 26 0;
#P newex 184 162 21 196617 t 1;
#P newex 25 212 21 196617 t 0;
#P newex 25 168 62 196617 route error;
#P newex 25 149 35 196617 error;
#P newex 25 128 60 196617 loadmess 1;
#P newex 154 128 40 196617 filein;
#P window linecount 2;
#P comment 67 258 98 196617 0 = file doesnt exist 1 = file exists;
#P connect 1 2 6 0;
#P connect 8 0 5 0;
#P connect 4 0 8 0;
#P connect 3 0 4 0;
#P connect 2 0 3 0;
#P connect 5 0 7 0;
#P fasten 6 0 7 0 189 241 30 241;
#P connect 10 0 1 0;
#P connect 11 0 1 0;
#P window clipboard copycount 13;


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