Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

creaking directories using mkdir function

Status
Not open for further replies.

nappaji

Programmer
Mar 21, 2001
76
0
0
US
On the unix command prompt, we can create multiple nested directories using the "mkdir -p" command.
i.e. if I want to create a directory ABC, then a directory 123 under ABC, then a directory xyz under 123, I can accomplish this using one single command using
mkdir -p ABC/123/xyz

I want to accomplish the same in C code. The mkdir C function doesnot allow me to create nested directories.
Is there a way to accomplish this??

I donot want to use the system ("mkdir -p ABC/123/xyz") command..

Any other methods???
 
Use a loop to call the C mkdir() one directory at a time

Code:
mkdir("ABC",0755);
mkdir("ABC/123",0755);
mkdir("ABC/123/xyz",0755);
 
Sure.
Create a wrapper for mkdir that accepts an array of
strings in the order of your creation then create them
one at a time appending the previous dirname and separator
to the next.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top