Forums > MaxMSP

using filepath – adding a sub directory

September 30, 2007 | 5:34 pm

Hello

Making a patch which automatically gets the file path of the patch itself to add it to the search paths so I can pick up images etc. I’m a little stuck as I need to add a folder name to the end of the retrieved path so that I can organise all my files into a folder i.e.

retrieved path:
the/path/to/this/patch/

becomes:
the/path/to/this/patch/files/

This is what I have so far and I thought I just needed to use append but it does not seem to work, any ideas?

max v2;
#N vpatcher 571 195 1171 595;
#P window setfont "Sans Serif" 9.;
#P newex 59 50 48 196617 loadbang;
#P message 59 73 27 196617 path;
#N thispatcher;
#Q end;
#P newobj 59 94 70 196617 thispatcher;
#B color 5;
#P window linecount 2;
#P comment 87 68 113 196617 Automatically retrieve current files path;
#P window linecount 1;
#P comment 78 299 143 196617 The Current search path 8;
#P comment 166 141 82 196617 Choose a folder;
#P message 67 313 352 196617 the/path/to/this/patch/;
#P button 151 140 15 0;
#P newex 151 215 60 196617 prepend set;
#P newex 151 195 63 196617 relativepath;
#P newex 151 158 74 196617 opendialog fold;
#P newex 172 254 84 196617 filepath search 8;
#B color 5;
#P comment 256 256 105 196617 Use as search path 8;
#P connect 12 0 11 0;
#P connect 11 0 10 0;
#P fasten 4 0 6 0 156 241 72 241;
#P connect 5 0 2 0;
#P fasten 10 1 3 0 124 185 156 185;
#P connect 2 0 3 0;
#P connect 3 0 4 0;
#P fasten 4 0 1 0 156 241 177 241;
#P pop;

any help much appreciated.

a+
gar


September 30, 2007 | 6:12 pm

[sprintf] is your friend.

check out this basic example patch…
/dan

max v2;
#N vpatcher 601 261 1201 661;
#P button 33 32 35 0;
#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P newex 33 81 30 196617 t b b;
#P window linecount 0;
#P message 99 280 16 196617;
#P window linecount 1;
#P newex 99 236 62 196617 prepend set;
#P newex 60 236 32 196617 print;
#P newex 60 201 72 196617 sprintf %s%s;
#P message 160 126 36 196617 files/;
#P message 33 126 123 196617 the/path/to/this/patch/;
#P comment 71 41 109 196617 Click to generate path;
#P connect 8 0 7 0;
#P connect 7 0 1 0;
#P connect 1 0 3 0;
#P connect 3 0 4 0;
#P connect 3 0 5 0;
#P connect 5 0 6 0;
#P connect 2 0 3 1;
#P connect 7 1 2 0;
#P pop;

Quote: Garrett wrote on Sun, 30 September 2007 11:34
—————————————————-
> Hello
>
> Making a patch which automatically gets the file path of the patch itself to add it to the search paths so I can pick up images etc. I’m a little stuck as I need to add a folder name to the end of the retrieved path so that I can organise all my files into a folder i.e.
>
> retrieved path:
> the/path/to/this/patch/
>
> becomes:
> the/path/to/this/patch/files/
>

> gar
—————————————————-


September 30, 2007 | 7:31 pm

Hello

yes that’s sorted it, below is the final result. thanks!!!

a+
gar

max v2;
#N vpatcher 571 195 1159 643;
#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P comment 307 148 82 196617 Choose a folder;
#P button 292 147 15 0;
#P newex 292 165 74 196617 opendialog fold;
#P newex 225 243 60 196617 prepend set;
#P message 137 264 35 196617 set $1;
#P newex 137 186 49 196617 tosymbol;
#B color 5;
#P newex 199 125 48 196617 loadbang;
#P newex 137 165 72 196617 sprintf %s%s;
#P message 199 146 36 196617 files/;
#P comment 78 356 143 196617 The Current search path 8;
#P message 67 370 352 196617 GarrettG5:/Users/garrett/Desktop/;
#P newex 137 243 80 196617 prepend symbol;
#P newex 137 215 63 196617 relativepath;
#P newex 225 273 84 196617 filepath search 8;
#B color 5;
#P comment 309 275 105 196617 Use as search path 8;
#P newex 59 50 48 196617 loadbang;
#P message 59 73 27 196617 path;
#N thispatcher;
#Q end;
#P newobj 59 94 70 196617 thispatcher;
#B color 5;
#P window linecount 2;
#P comment 87 68 113 196617 Automatically retrieve current files path;
#P connect 3 0 2 0;
#P connect 2 0 1 0;
#P fasten 14 0 8 0 142 332 72 332;
#P connect 1 1 11 0;
#P connect 11 0 13 0;
#P connect 13 0 6 0;
#P fasten 16 0 6 0 297 208 142 208;
#P connect 6 0 7 0;
#P connect 7 0 14 0;
#P connect 12 0 10 0;
#P connect 10 0 11 1;
#P fasten 6 0 15 0 142 237 230 237;
#P connect 15 0 5 0;
#P connect 17 0 16 0;
#P pop;


September 30, 2007 | 10:38 pm

Something else to consider….

I would highly recommend using a single loadbang attached to a trigger to manage this operation. Right now the 2 loadbangs are independent, and this could cause you problems if you start using code like this in larger patches. If, somehow, the "path" message triggers first, then your sprintf object will put out the path without the folder appended… and then afterwards when the "files/" is banged, there will be no output at all.

The patch below shows what I mean…
/dan

max v2;
#N vpatcher 571 195 1159 643;
#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P newex 137 52 30 196617 t b b;
#P comment 307 148 82 196617 Choose a folder;
#P button 292 147 15 0;
#P newex 292 165 74 196617 opendialog fold;
#P newex 225 243 60 196617 prepend set;
#P message 137 264 35 196617 set $1;
#P newex 137 186 49 196617 tosymbol;
#B color 5;
#P newex 137 165 72 196617 sprintf %s%s;
#P message 222 94 36 196617 files/;
#P comment 78 356 143 196617 The Current search path 8;
#P message 67 370 352 196617 GarrettG5:/Users/garrett/Desktop/;
#P newex 137 243 80 196617 prepend symbol;
#P newex 137 215 63 196617 relativepath;
#P newex 225 273 84 196617 filepath search 8;
#B color 5;
#P comment 309 275 105 196617 Use as search path 8;
#P newex 137 28 48 196617 loadbang;
#P message 58 89 27 196617 path;
#N thispatcher;
#Q end;
#P newobj 58 110 70 196617 thispatcher;
#B color 5;
#P window linecount 2;
#P comment 86 84 113 196617 Automatically retrieve current files path;
#P comment 177 52 197 196617 right-to-left order guarantees that sprintf will receive "files/" before the path;
#P connect 19 0 3 0;
#P connect 3 0 2 0;
#P fasten 14 0 9 0 142 332 72 332;
#P connect 4 0 19 0;
#P connect 2 1 12 0;
#P connect 12 0 13 0;
#P fasten 16 0 7 0 297 208 142 208;
#P connect 13 0 7 0;
#P connect 7 0 8 0;
#P connect 8 0 14 0;
#P connect 11 0 12 1;
#P connect 19 1 11 0;
#P fasten 7 0 15 0 142 237 230 237;
#P connect 15 0 6 0;
#P connect 17 0 16 0;
#P pop;


October 2, 2007 | 4:36 pm

Hi

your right and it did start doing this, i need to start using t b b more often, I always forget about the right to left order. anyway i did this which seems to work just as well

max v2;
#N vpatcher 501 322 1101 722;
#P origin 0 -87;
#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P newex 98 45 48 196617 loadbang;
#P message 98 68 27 196617 path;
#N thispatcher;
#Q end;
#P newobj 98 89 70 196617 thispatcher;
#B color 5;
#P window linecount 2;
#P comment 126 63 113 196617 Automatically retrieve current files path;
#P window linecount 1;
#P comment 328 106 82 196617 Choose a folder;
#P button 313 105 15 0;
#P newex 313 123 74 196617 opendialog fold;
#P newex 246 203 60 196617 prepend set;
#P message 158 224 35 196617 set $1;
#P newex 158 146 49 196617 tosymbol;
#B color 5;
#P newex 158 125 84 196617 sprintf %sfiles/;
#P comment 99 316 143 196617 The Current search path 8;
#P window linecount 2;
#P message 88 330 352 196617 "GarrettG5:/Users/garrett/Desktop/network performance/research/tests/files/";
#P window linecount 1;
#P newex 158 203 80 196617 prepend symbol;
#P newex 158 175 63 196617 relativepath;
#P newex 246 233 84 196617 filepath search 8;
#B color 5;
#P comment 330 235 105 196617 Use as search path 8;
#P fasten 8 0 4 0 163 292 93 292;
#P connect 16 0 15 0;
#P connect 15 0 14 0;
#P connect 14 1 6 0;
#P connect 6 0 7 0;
#P fasten 10 0 2 0 318 168 163 168;
#P connect 7 0 2 0;
#P connect 2 0 3 0;
#P connect 3 0 8 0;
#P fasten 2 0 9 0 163 197 251 197;
#P connect 9 0 1 0;
#P connect 11 0 10 0;
#P pop;

thanks for your help

a+
gar


October 2, 2007 | 4:40 pm

scratch that, yours wins :)

a+
gar


October 2, 2007 | 4:50 pm

mmm is there something about thispatcher that makes it not work in collectives or max runtime, can’t seem to retrieve the path from thispatcher with your patch or mine.

a+
gar


October 2, 2007 | 9:36 pm

Hi

Need to detect the path of the current file / app regardless of whether its running as a patch, collective or app. This is what I have so far which works for patches and apps but not collectives:

max v2;
#N vpatcher 422 44 1089 541;
#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P newex 221 119 40 196617 t b b b;
#P newex 275 339 52 196617 r apppath;
#P window linecount 2;
#P message 274 294 130 196617 ; max sendapppath apppath;
#P user gswitch2 220 215 39 32 0 0;
#P window linecount 1;
#P newex 221 98 48 196617 loadbang;
#P message 170 277 27 196617 path;
#N thispatcher;
#Q end;
#P newobj 170 298 70 196617 thispatcher;
#B color 5;
#P window linecount 3;
#P comment 276 191 96 196617 Automatically retrieve current files path;
#P window linecount 1;
#N vpatcher 666 579 1153 1000;
#P window setfont "Sans Serif" 9.;
#P message 192 136 36 196617 files/;
#P inlet 192 60 15 0;
#P comment 154 61 46 196617 Bang in;
#P comment 300 139 82 196617 Choose a folder;
#P button 285 138 15 0;
#P newex 285 156 74 196617 opendialog fold;
#P newex 218 236 60 196617 prepend set;
#P message 130 257 35 196617 set $1;
#P newex 130 179 49 196617 tosymbol;
#B color 5;
#P newex 130 158 72 196617 sprintf %s%s;
#P comment 71 349 143 196617 The Current search path 8;
#P inlet 130 60 15 0;
#P comment 92 61 46 196617 Path in;
#P user panel 60 38 352 58;
#X brgb 255 255 255;
#X frgb 255 0 0;
#X border 2;
#X rounded 0;
#X shadow 0;
#X done;
#P message 60 363 352 196617 ./files/;
#P newex 130 236 80 196617 prepend symbol;
#P newex 130 208 63 196617 relativepath;
#P newex 218 266 84 196617 filepath search 8;
#B color 5;
#P comment 302 268 105 196617 Use as search path 8;
#P fasten 11 0 4 0 135 325 65 325;
#P connect 7 0 9 0;
#P connect 9 0 10 0;
#P fasten 13 0 2 0 290 201 135 201;
#P connect 10 0 2 0;
#P connect 2 0 3 0;
#P connect 3 0 11 0;
#P connect 17 0 18 0;
#P connect 18 0 9 1;
#P fasten 2 0 12 0 135 230 223 230;
#P connect 12 0 1 0;
#P connect 14 0 13 0;
#P pop;
#P newobj 222 411 57 196617 p filepaths;
#P user panel 489 36 157 132;
#X brgb 255 255 255;
#X frgb 255 0 0;
#X border 5;
#X rounded 0;
#X shadow 0;
#X done;
#P newex 220 182 53 196617 r runtime;
#P button 221 76 15 0;
#P window linecount 2;
#P message 221 140 126 196617 ; max getruntime runtime;
#P connect 9 0 7 0;
#P connect 7 0 6 0;
#P connect 2 0 9 0;
#P connect 1 0 8 0;
#P connect 8 0 12 0;
#P connect 12 0 0 0;
#P connect 11 0 4 0;
#P connect 6 1 4 0;
#P connect 12 1 9 1;
#P connect 12 2 4 1;
#P connect 9 1 10 0;
#P pop;

thispatcher does not seem to work for collectives and using apppath returns the path of max runtime when I actually need the path of the collective itself – is there a way to do this?

a+
gar


October 2, 2007 | 10:06 pm

hi

if you look at the files preferences patch, you can see that a "1" is appended to the "set /path/to/dir/" message to [filepath].
this seems to automatically include subdirectories.
here is how i do :

#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P message 159 118 29 196617 path;
#P hidden newex 210 158 65 196617 relativepath;
#P hidden newex 210 227 86 196617 filepath search 0;
#P hidden newex 210 204 62 196617 prepend set;
#P hidden newex 210 181 49 196617 append 1;
#N thispatcher;
#Q end;
#P hidden newobj 159 136 61 196617 thispatcher;
#P connect 5 0 0 0;
#P hidden connect 0 1 4 0;
#P hidden connect 4 0 1 0;
#P hidden connect 1 0 2 0;
#P hidden connect 2 0 3 0;
#P window clipboard copycount 6;

this seems to work well… the "0" slot isn’t writed in the paths text file.

g


October 3, 2007 | 7:39 am

hi guys
i have or had the same problem with file paths and i was going to post a new post but i think is on the same subject in a way.

i want my files to load from a folder inside the patch folder

eg patch folder C:/_videolooper/

folder inside patch folder videomat/

full path C:/_videolooper/videomat/

then load file names to jit.cellblock and at the same time load into a poly~ movie object that im working on.

my problem is loading files in into poly~ with the same seg that are loaded into jit.cellblock
any help would be appreciated

thank for your time
dan.r

max v2;
#N vpatcher 467 49 1332 965;
#P origin -799 -98;
#P window setfont "Sans Serif" 9.;
#P comment 426 718 100 9109513 this way work but not acurate , it gets messed up;
#P window linecount 1;
#P newex 270 849 26 9109513 print;
#P newex 269 709 27 9109513 t b l;
#P comment 562 176 93 9109513 eg:C:/_videolooper/;
#P window linecount 2;
#P comment 532 287 153 9109513 folder name inside C:/_videolooper/ with material;
#P window linecount 1;
#P message 573 740 239 9109513 target 5 , read C:/_videolooper/videomat/anyname.mov;
#B color 7;
#P window linecount 2;
#P comment 545 448 153 9109513 3 sends movie names to jit.cellblock;
#P window linecount 0;
#P message 270 783 15 9109513;
#P window linecount 1;
#P message 286 739 104 9109513 set target $1 \, read $3;
#P newex 105 382 66 9109513 r frombrowser;
#P newex 145 325 68 9109513 s frombrowser;
#P newex 226 20 54 9109513 r tobrowser;
#P newex 559 666 56 9109513 s tobrowser;
#P number 167 563 35 9 0 0 0 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 139 496 38 9109513 unpack;
#P newex 269 683 214 9109513 sprintf %ld read C:/_videolooper/videomat/%s%s;
#P newex 287 426 45 9109513 loadbang;
#P message 375 476 32 9109513 types;
#P newex 202 488 60 9109513 prepend set;
#P newex 139 462 73 9109513 zl slice 2;
#P window linecount 0;
#P message 202 517 15 9109513;
#P window linecount 1;
#P newex 447 247 40 9109513 t b s b;
#P newex 491 219 51 9109513 tosymbol;
#P message 440 176 29 9109513 path;
#N thispatcher;
#Q end;
#P newobj 440 195 61 9109513 thispatcher;
#P message 477 287 47 9109513 videomat;
#P newex 426 349 51 9109513 tosymbol;
#P newex 426 318 61 9109513 sprintf %s%s;
#P newex 426 528 67 9109513 route append;
#P message 179 14 40 9109513 clear all;
#P newex 426 493 32 9109513 folder;
#P newex 426 449 55 9109513 t l b 0 clear;
#P newex 426 632 65 9109513 prepend set 0;
#P newex 523 583 45 9109513 + 1;
#P newex 426 608 51 9109513 pack i s;
#P newex 426 584 87 9109513 i;
#P newex 426 558 51 9109513 t b s;
#P user jit.cellblock 226 56 397 312 3 9 1 16 534 15 0 1 1 0 1 0 1 1 1 17 17 17 170 170 170 99 99 99 0 0 0 191 191 191 0 0 0 255 255 0 1 0 1 0 4 0 0 0;
#P comment 484 175 75 9109513 patch path;
#P window linecount 7;
#P comment 112 683 100 9109513 i need help in this part here…is there a better way of doing it? what im after is as files LOAD in jit.cellblock to load into poly at same time in the same seg;
#P user panel 216 670 331 145;
#X brgb 241 139 139;
#X frgb 0 0 0;
#X border 1;
#X rounded 0;
#X shadow 0;
#X done;
#P window linecount 3;
#P comment 625 696 100 9109513 this is the massage that i want to send to poly;
#P fasten 32 0 22 0 110 425 144 425;
#P connect 22 0 27 0;
#P fasten 4 0 31 0 231 319 150 319;
#P connect 27 1 28 0;
#P connect 22 1 23 0;
#P connect 23 0 21 0;
#P connect 30 0 4 0;
#P connect 12 0 4 0;
#P fasten 6 0 26 0 431 605 274 605;
#P connect 26 0 39 0;
#P connect 39 0 34 0;
#P connect 33 0 34 0;
#P connect 34 0 40 0;
#P connect 39 1 33 0;
#P fasten 5 1 26 1 472 581 376 581;
#P fasten 25 0 24 0 292 463 380 463;
#P fasten 20 1 14 0 467 282 431 282;
#P connect 14 0 15 0;
#P connect 15 0 10 0;
#P connect 24 0 11 0;
#P connect 10 0 11 0;
#P connect 11 0 13 0;
#P fasten 10 1 13 0 446 489 464 489 464 521 431 521;
#P connect 13 0 5 0;
#P connect 5 0 6 0;
#P connect 6 0 7 0;
#P connect 7 0 9 0;
#P connect 18 0 17 0;
#P fasten 19 0 20 0 496 244 452 244;
#P connect 5 1 7 1;
#P fasten 20 2 16 0 482 278 482 278;
#P fasten 20 0 16 0 452 281 482 281;
#P connect 16 0 14 1;
#P connect 17 1 19 0;
#P fasten 10 2 6 1 461 484 508 484;
#P connect 8 0 6 1;
#P connect 6 0 8 0;
#P fasten 9 0 29 0 431 662 564 662;
#P fasten 10 3 29 0 476 475 564 475;
#P pop;


October 3, 2007 | 11:49 am

Quote: G. wrote on Tue, 02 October 2007 23:06
—————————————————-
> hi
>
> if you look at the files preferences patch, you can see that a "1" is appended to the "set /path/to/dir/" message to [filepath].
> this seems to automatically include subdirectories.
> here is how i do :
—————————————————-

hi

useful to know but not sure how this relates to the question of retrieving a files path regardless of whether its a patch / collective / app. Anyway I’ve discovered that both collectives and apps by default have their own path so i simply have to test whether it’s a patch or not, if its not then do nothing. This seems correct:

max v2;
#N vpatcher 422 44 859 381;
#P window setfont "Sans Serif" 9.;
#P message 240 216 98 196617 automatically found;
#P user gswitch2 169 178 39 32 0 0;
#P newex 240 236 95 196617 print searchpath-8;
#P button 258 61 15 0;
#P window linecount 2;
#P message 258 79 54 196617 ; max paths;
#P window linecount 1;
#P newex 198 101 40 196617 t b b b;
#P newex 198 80 48 196617 loadbang;
#P message 134 215 27 196617 path;
#N thispatcher;
#Q end;
#P newobj 134 236 70 196617 thispatcher;
#B color 5;
#P window linecount 3;
#P comment 115 80 82 196617 Automatically retrieve current files path;
#P window linecount 1;
#N vpatcher 666 579 1153 1000;
#P window setfont "Sans Serif" 9.;
#P newex 31 238 95 196617 print searchpath-8;
#P newex 218 236 45 196617 append 1;
#P message 192 136 36 196617 files/;
#P inlet 192 60 15 0;
#P comment 154 61 46 196617 Bang in;
#P comment 300 139 82 196617 Choose a folder;
#P button 285 138 15 0;
#P newex 285 156 74 196617 opendialog fold;
#P newex 218 259 60 196617 prepend set;
#P message 130 259 35 196617 set $1;
#P newex 130 179 49 196617 tosymbol;
#B color 5;
#P newex 130 158 72 196617 sprintf %s%s;
#P comment 71 349 143 196617 The Current search path 8;
#P inlet 130 60 15 0;
#P comment 92 61 46 196617 Path in;
#P user panel 60 38 352 58;
#X brgb 255 255 255;
#X frgb 255 0 0;
#X border 2;
#X rounded 0;
#X shadow 0;
#X done;
#P message 60 363 396 196617 "GarrettG5:/Users/garrett/Desktop/network performance/research/tests/files/";
#P newex 130 238 80 196617 prepend symbol;
#P newex 130 208 63 196617 relativepath;
#P newex 218 281 84 196617 filepath search 8;
#B color 5;
#P comment 302 283 105 196617 Use as search path 8;
#P connect 2 0 20 0;
#P fasten 11 0 4 0 135 325 65 325;
#P connect 7 0 9 0;
#P connect 9 0 10 0;
#P fasten 13 0 2 0 290 201 135 201;
#P connect 10 0 2 0;
#P connect 2 0 3 0;
#P connect 3 0 11 0;
#P connect 17 0 18 0;
#P connect 18 0 9 1;
#P fasten 2 0 19 0 135 230 223 230;
#P connect 19 0 12 0;
#P connect 12 0 1 0;
#P connect 14 0 13 0;
#P pop;
#P newobj 194 261 57 196617 p filepaths;
#P newex 130 156 53 196617 r runtime;
#P button 198 62 15 0;
#P window linecount 2;
#P message 58 125 126 196617 ; max getruntime runtime;
#P window linecount 1;
#P comment 274 62 100 196617 test paths checked;
#P user panel 47 51 341 238;
#X brgb 255 255 255;
#X frgb 255 0 0;
#X border 5;
#X rounded 0;
#X shadow 0;
#X done;
#P fasten 10 1 2 0 218 121 63 121;
#P fasten 14 0 8 0 174 212 139 212;
#P connect 8 0 7 0;
#P fasten 4 0 14 0 135 175 174 175;
#P connect 7 1 5 0;
#P connect 3 0 9 0;
#P connect 9 0 10 0;
#P connect 10 0 14 1;
#P fasten 14 1 15 0 203 212 245 212;
#P connect 15 0 13 0;
#P fasten 10 2 5 1 233 257 246 257;
#P connect 12 0 11 0;
#P pop;


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