1

I want to create some files inside a directory in C with minimal code size.

For example, if my current directory is foo and I want to create foo/bar/file1.txt, I can not use fopen("bar/file1.txt", "w"); to create the bar/ directory and the file in a single line.

How can I achieve this without making a function that parses the path to the file and for each firectory uses mkdir if it does not exist? I am looking for a "touch" like behavior without using system() ?

George Sp
  • 553
  • 5
  • 20
  • 4
    Possible duplicate of [How can I create directory tree in C++/Linux?](https://stackoverflow.com/q/675039/608639), [Create a file and its parents directories in C](https://stackoverflow.com/q/28247719/608639), [How to create file inside a directory using C](https://stackoverflow.com/q/22949500/608639), etc. – jww Mar 29 '19 at 20:33
  • @jww I have seen this post but I am looking for a "one-liner" not a function. But thank you for the comment. – George Sp Mar 29 '19 at 20:38
  • 1
    "I am looking for a "touch" like behavior without using system() ?" - If you are looking for syscall with such behavior, then it doesn't exist. If you are looking for some library which has such functionality, then referenced question has some suitable answers, like this: https://stackoverflow.com/a/675095/3440745. – Tsyvarev Mar 29 '19 at 20:56

0 Answers0