relative search path for loading samples

kampana's icon

Hi,

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...

thanks.

AlexHarker's icon

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...

Alex

Max Patch
Copy patch and select New From Clipboard in Max.

kampana's icon

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

seejayjames's icon

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.

AlexHarker's icon

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

kampana's icon

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!