create file directly
-
In my app I need to write something in some place on PC. In my code I call 'std::ofstream' but first I have to make sure that file exist. If file doesn't exist I need to make an empty file. Now my question is, after I find out that file doesn't exist can I create it only by specifying full path-name not worrying if some of sub folders exist. It needs to recreate the whole path. To be more specific the location is 'C:\....\Aplication Data\..". How to achieve this? Thanks
-
In my app I need to write something in some place on PC. In my code I call 'std::ofstream' but first I have to make sure that file exist. If file doesn't exist I need to make an empty file. Now my question is, after I find out that file doesn't exist can I create it only by specifying full path-name not worrying if some of sub folders exist. It needs to recreate the whole path. To be more specific the location is 'C:\....\Aplication Data\..". How to achieve this? Thanks
Use
SHCreateDirectory
to create the entire path before creating the file.«_Superman_»
-
In my app I need to write something in some place on PC. In my code I call 'std::ofstream' but first I have to make sure that file exist. If file doesn't exist I need to make an empty file. Now my question is, after I find out that file doesn't exist can I create it only by specifying full path-name not worrying if some of sub folders exist. It needs to recreate the whole path. To be more specific the location is 'C:\....\Aplication Data\..". How to achieve this? Thanks
josip cagalj wrote:
Now my question is, after I find out that file doesn't exist can I create it only by specifying full path-name not worrying if some of sub folders exist. It needs to recreate the whole path.
You'll have to do that separately from the file create. And even the functions you could use to create a directory (
_mkdir
orCreateDirectory
) will only create a directory if its parent exists. So you're going to have to write something that recurses through a path, creating directories that don't exist in teh appropriate order.Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
-
josip cagalj wrote:
Now my question is, after I find out that file doesn't exist can I create it only by specifying full path-name not worrying if some of sub folders exist. It needs to recreate the whole path.
You'll have to do that separately from the file create. And even the functions you could use to create a directory (
_mkdir
orCreateDirectory
) will only create a directory if its parent exists. So you're going to have to write something that recurses through a path, creating directories that don't exist in teh appropriate order.Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
Thanks to all of you!
-
josip cagalj wrote:
Now my question is, after I find out that file doesn't exist can I create it only by specifying full path-name not worrying if some of sub folders exist. It needs to recreate the whole path.
You'll have to do that separately from the file create. And even the functions you could use to create a directory (
_mkdir
orCreateDirectory
) will only create a directory if its parent exists. So you're going to have to write something that recurses through a path, creating directories that don't exist in teh appropriate order.Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
Stuart Dootson wrote:
And even the functions you could use to create a directory (_mkdir or CreateDirectory) will only create a directory if its parent exists.
SHCreateDirectory
will create the entire path for you.«_Superman_»
-
Stuart Dootson wrote:
And even the functions you could use to create a directory (_mkdir or CreateDirectory) will only create a directory if its parent exists.
SHCreateDirectory
will create the entire path for you.«_Superman_»