Determine if the directory exists

xiaoxiao2021-03-05  19

Determine if the directory exists

When writing logs, you can often use a directory such as log, by calling

Dir * OpenDir (const char * p A t h n a m e);

This function is to determine if the specified directory exists, and there is no existence.

INT MKDIR (const char * p A t h n a m e, MODE_T M o D E);

Create this directory. One of the small programs below is an example of a directory operation:

#include #include #include #include #include int main (int Argc, char * argv [] ) {IF (argc! = 2) {fprintf (stderr, "usage: Dir Director / N"); return -1;} DIR * DIR = OpenDir (Argv [1]); if (Dir == Null) {Printf ("% s not director / n", argv [1]); // creAe a Director Mkdir (Argv [1], S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); Printf ("Make Director S / N", Argv [1]); RETURN-1;} Printf ("% s is exist./n", argv [1]); Closedir (DIR); return 0;}

转载请注明原文地址:https://www.9cbs.com/read-38594.html

New Post(0)