How to create folders in a patch?

Jul 10, 2007 at 3:10pm

How to create folders in a patch?


We need to create folders from a Max patch on both OSX (universal) and Windows.

1) are they any standard and simple (no java based..) way to do that?

2) are they any third party objects available?

3) we tried to develop our C external but get very confused by the path syntax (like “MacOSX Tiger:/Applications/toto”) that mixes “:” and “/” separators). Moreover the “conformpath” help says that “old colon style format” and “the new slash style” may be used… Are they any *clear* explanations of path management in Max, and of what external code would be supposed to do?


Stephane Letz

Jul 10, 2007 at 4:00pm

on os x, use the shell exterenal and send it the message:
“mkdir /path/to/new/directory”

Jul 10, 2007 at 4:15pm

I need to create folders with accentued letters and spaces… not the unix way

Jul 11, 2007 at 9:41am

OS X only – this is where the platforms are really different

below’s the function, it even uses max’s path utilities…




void createfolder_anything(t_createfolder *x, t_symbol *s, long ac,
t_atom *av)
long len, pos = 0;
short path = 0;
char *charptr;
char name[2048];
char inname[2048];
char parentname[2048];
char foldername[2048];
const FSRef parentRef;
CFStringRef str;
HFSUniStr255 folderNameU;
OSStatus err;
Boolean isDirectory;
long result = 0;

path_nameconform(s->s_name, inname, PATH_STYLE_SLASH, PATH_TYPE_BOOT);
if(x->t_debug) post(“path namecomform returns %s”, inname);

len = strlen(inname);
if(inname[len-1] == ‘/’) {
inname[len-1] = 0;
if (path_topathname(path, inname, name)) { // check if path alreay
charptr = strrchr(inname, ‘/’);
if(charptr != NULL){
pos = (long)(charptr – inname + 1);
charptr = (char *)memmove(foldername, (inname + pos), (len – pos));
foldername[(len - pos)] = 0;
inname[MIN(len, pos)] = 0;
strcpy(parentname, inname);
if(x->t_debug) post(“parentname is %s — foldername is %s”,
parentname, foldername);

err = FSPathMakeRef((const UInt8*)parentname, &parentRef,
if((err == noErr) && (isDirectory)) {

if(x->t_debug) post(“makeFS returned noErr and isDirectory”);

str = CFStringCreateWithCString(kCFAllocatorDefault, foldername,
// encoding constant is important : shouldn’t it come from

folderNameU.length = (UInt16)CFStringGetLength(str);
CFStringGetCharacters(str, CFRangeMake(0, folderNameU.length),

// see if it already exists?
err = FSMakeFSRefUnicode(&parentRef,
kTextEncodingUnicodeDefault, NULL);
// should now verify that is, in fact, a folder.

if (err != noErr) { // no, so try to create it.
err = FSCreateDirectoryUnicode(&parentRef, folderNameU.length,
result = 1;
} else {
if(x->t_debug) post(“makeFS failed: %ld and %ld “,(int)err,
result = 0;
outlet_int(x->t_outlet, result);

Jul 11, 2007 at 11:49am

Jul 11, 2007 at 12:02pm

Jul 11, 2007 at 12:17pm


You must be logged in to reply to this topic.