Category : File Managers
Archive   : UNIXFIND.ZIP
Filename : ENSURE.C

 
Output of file : ENSURE.C contained in archive : UNIXFIND.ZIP

#include
#include
#include

#ifndef DEBUG
extern
#endif
char pathchar;

/*
* Ensure that a given pathname exists.
*/
void ensure_exists(char *path)
{
char *ep;
struct ffblk ff;

if (!findfirst(path, &ff, FA_DIREC) && (ff.ff_attrib & FA_DIREC) != 0) return;

for (ep = path + strlen(path); *ep != pathchar && ep != path; ep--)
;
if (*ep == pathchar) {
*ep = '\0';
ensure_exists(path);
*ep = pathchar;
}
mkdir(path);
}


#ifdef DEBUG
main(int argc, char *argv[])
{
pathchar = (getswitchar() == '/')? '\\': '/';
if (argc < 2) {
printf("usage: ensure pathname\n");
exit(0);
}
return ensure_exists(argv[1]);
}
#endif