relative search path for loading samples

Mar 28, 2010 at 7:23pm

relative search path for loading samples


i need a quick simple way to load sample files into buffer~ based on the relative path of the patch. for example, “read ../samples/sample1.wav” would read that file from the /samples subfolder inside the patch folder. isn’t there a way to temporarily add a folder to Max’s search path? i’ve tried using Filepath object, but seems like it needs to receive messages with a computer-specific filepath, and my patch is intended to move around between several computers.

i’ve done it before, but for some reason can’t figure out how to do it again! help please…


Mar 28, 2010 at 7:31pm

Sorry for the old school format, but I had this lying around in Max 4 format. Place it in the patch and it should add your folder to the searchpath on loadbang…


#P window setfont “Sans Serif” 9.;
#P window linecount 1;
#N vpatcher 10 59 332 246;
#P window setfont “Sans Serif” 9.;
#P window linecount 1;
#P newex 23 71 49 196617 append 1;
#P newex 23 49 78 196617 prepend append;
#P newex 23 92 77 196617 filepath search;
#P newex 24 114 73 196617 loadmess path;
#N comlet From thispatcher Path;
#P inlet 23 29 15 0;
#N comlet To thispatcher;
#P outlet 24 136 15 0;
#P connect 1 0 4 0;
#P connect 4 0 5 0;
#P connect 5 0 3 0;
#P connect 2 0 0 0;
#P pop;
#P hidden newobj 332 77 75 196617 p Search_Path;
#N thispatcher;
#Q end;
#P hidden newobj 281 55 61 196617 thispatcher;
#P hidden fasten 1 0 0 0 337 98 278 98 278 51 286 51;
#P hidden connect 0 1 1 0;
#P window clipboard copycount 2;

Mar 28, 2010 at 9:14pm

thanks for your reply!
when i add this piece to my patch, Max says “cannot build search path from root directory” …

Mar 28, 2010 at 9:26pm

try loadbanging a “path” message to [thispatcher], then you need to use [sprintf] to create the path (as a single symbol, so no spaces will mess it up… as a general rule, to avoid spaces messing things up like this, put quotes around things). There’s an example in the [sprintf] help file:

sprintf symout %s%s

where the first %s is the path as a single symbol, and the second %s is your filename. Then run this through [prepend open] and into your buffer~.

There’s also the adding a filepath option, but this works too.

Mar 28, 2010 at 9:45pm

Is your main patch in your root directory? that may not be allowed…..

Mar 29, 2010 at 10:05am

it’s not in the root dir so i don’t know what makes Max output that error. but anyway, i’ve worked it out using sprintf. thanks!


You must be logged in to reply to this topic.