[gameprogrammer] Re: Linux equivalent of CreateDirectory

  • From: "Kevin Jenkins" <gameprogrammer@xxxxxxxxxx>
  • To: <gameprogrammer@xxxxxxxxxxxxx>
  • Date: Sat, 10 Jul 2004 14:51:45 -0700

This is what I wrote.  I'm actually running on windows so have no way to
test it.  Hope it works :)

bool CreateFileWithDirectories(const char *path, char *data, unsigned
dataLength)

{

int index;

FILE *fp;

char *pathCopy;

#ifndef _WIN32

char *systemCommand;

#endif

if (path==0 || path[0]==0 || data==0 || dataLength<=0)

return false;


#ifndef _WIN32

systemCommand = new char [strlen(path)+1 + 6];

#endif

pathCopy = new char [strlen(path)+1];

strcpy(pathCopy, path);

index = 0;

while (pathCopy[index])

{

if (pathCopy[index]=='/' || pathCopy[index]=='\\')

{

pathCopy[index]=0;

#ifdef _WIN32

CreateDirectory(pathCopy, 0);

#else

strcpy(systemCommand, "mkdir ");

strcat(systemCommand, pathCopy);

system(systemCommand);

#endif

pathCopy[index]='/';

}

index++;

}

delete [] pathCopy;

#ifndef _WIN32

delete [] systemCommand;

#endif

fp = fopen(path, "wb");

if (fp==0)

return false;

fwrite(data, 1, dataLength, fp);

fclose(fp);

return true;

}



---------------------
To unsubscribe go to http://gameprogrammer.com/mailinglist.html


Other related posts: