-4

I want to create a file. Is there any function which can create the file including the complete nested directories (the directories may not exist)? Or I need to create the nested directories first?

Thanks in advance.

baila
  • 51
  • 1
  • 1
  • 6
  • http://stackoverflow.com/questions/1530760/how-do-i-recursively-create-a-folder-in-win32 or http://stackoverflow.com/questions/675039/how-can-i-create-directory-tree-in-c-linux – Retired Ninja Mar 08 '15 at 07:49
  • I have already viewed those. I want to know whether there is any single function call to do my job. Thanks for your reply. – baila Mar 08 '15 at 07:52
  • Since you didn't post your code it's hard to guess how to improve it. I don't know of any way to do it other than to create the directories first. – Retired Ninja Mar 08 '15 at 07:56
  • Directories are an operating system specific thing. But see ` ` from latest C++14 (or future C+17) specification. C++11 could exist on a system without any directory (even if I know no such implementation) – Basile Starynkevitch Mar 08 '15 at 08:00
  • So please edit your question to improve it: which C++ standard? which operating system? Which compiler? – Basile Starynkevitch Mar 08 '15 at 08:01

1 Answers1

2

There are no standard C++ library functions to work with directories. I can think of the following third party libraries to help you with that:

  1. Boost - http://www.boost.org/doc/libs/1_57_0/libs/filesystem/doc/index.htm
  2. Qt - http://qt-project.org/doc/qt-4.8/qdir.html

If you have access to the POSIX libraries, if you are working in Linux you do, you can use the directory manipulation function from it:

opendir
readdir
closedir
mkdir

R Sahu
  • 204,454
  • 14
  • 159
  • 270
  • No, I don't want to include any third party library. I have already made nested folders and my desired file. I am eager to know that whether any build-in function can replace my those codes. Thanks for your reply. – baila Mar 08 '15 at 07:54
  • The point is that standard C++11 implementation could exist on a system which does not have any directory (even if I know no such system today) – Basile Starynkevitch Mar 08 '15 at 07:58
  • @balla: you cannot do that in pure standard C++11. You need some additional libraries (perhaps the operating system library). – Basile Starynkevitch Mar 08 '15 at 08:03