Directory Tree Creation

Mar 8, 2012 at 5:36am
I wanted to create a directory with a specified path but using CreateDirectory api alone didn't help much.

Tried this one but no avail:

1
2
3
char *pzPath = "c:\\abc\\def\\ghi";

CreateDirectoryA(path, NULL);


Do i need to parse all string for directory and create those path one by one?
Is there an easy way to make a directory tree like use one api only?

Some sample would be nice :)

Last edited on Mar 8, 2012 at 5:36am
Mar 8, 2012 at 11:10am
try this
1
2
int Error = CreateDirectoryA(path,NULL);
cout << Error;


the o/p should be 0. If not then call GetLastError() function.

note:
the abc and def directory should exist. Otherwise the call would fail.
Mar 8, 2012 at 1:33pm
The CreateDirectory function only creates the final directory in the specified path (assuming the rest of the path exists): http://msdn.microsoft.com/en-us/library/windows/desktop/aa363855(v=vs.85).aspx

You will need to either:
1. Parse the path string and create each nested directory in turn
2. Use the SHCreateDirectoryEx function from the Shell API

See here:
http://msdn.microsoft.com/en-us/library/ms647698.aspx

Mar 9, 2012 at 3:13am
@Lodger

I basically read SHCreateDirectoryEx api info on msdn and found out it works best


Thanks for both of you guys reply
Last edited on Mar 9, 2012 at 3:14am
Topic archived. No new replies allowed.