I want to create a file on linux system in my program, say /a/b/c/test, currently I only have dir /a exist and I want to do it in my program, is there any function that can create file as well as missing dirs (that is, create b/c/test) in one deal? open, fopen, mkdir all seem can’t work if there are missing dirs along the path. Thank you.
Share
From
strace mkdir -p a/b/c:In other words, you have to call
mkdir()yourself, in a loop per directory, then create the file. This is how themkdirexe does it (in C). Why not run themkdir -p /a/b/ccommand withexecve? With C stuff set up for the call properly, of course.