Search code examples
cdirectorymkdir

Programmatically Recursively Make Directory


I want my program to create a file located at the path of the command parameter, i.e. program /home/user/directory/that/doesnt/exist/file. If the directory doesn't exist, fopen will fail to open the file, so the program would have to create the directories. Would I have to program my own loop to detect each slash and mkdir each directory or is there a function to do this automatically?


Solution

  • Someone coded it for you: mkpath()

    Or if you're satisfied using system(), then you can use system("mkdir -p /your/path/here");