CreateDirectory doesn't work...

I am trying to use the CreateDirectory function to create a directory structure. Is this allowed? For example, I have a directory now called d:\temp. I want to create upto d:\temp\dir1\dir2\dir3 in one go.

I have tried to create even one directory by CreateDirectory seems to fail with the following error message:
"Invalid Access to Memory Location".

My code looks like this:
SECURITY_ATTRIBUTES sAtr;
sAtr.nLength = sizeof(SECURITY_ATTRIBUTES);
BOOL bDirDone = CreateDirectory("d:\\Temp\\dir1\\dir2\\dir3", &sAtr);

Whats going wrong??
baigmzAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

akalmaniCommented:
Hope this helps u out ?
U can't create a number of directory at once, this piece of code would help u ...
The security attributes may be as u specified with any attributes or NULL.
BOOL bDirDone = CreateDirectory("\\?\D:\Temp\dir1",NULL) ;
bDirDone = CreateDirectory("\\?\D:\Temp\dir1\dir2",NULL) ;
bDirDone = CreateDirectory("\\?\D:\Temp\dir1\dir2\dir3",NULL) ;
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
baigmzAuthor Commented:
I tried this one. Its only a wide format for the file name to enable more than 248 chars in the filename. It doesn't make a difference.
0
vachoohoCommented:
YOu use UNICODE build?

If so
place characters into _T() macro

thus

CreateDirectory(_T("d:\\temp\\dir211"));

This should help.
0
Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

vachoohoCommented:
SECURITY_ATTRIBUTES sAtr;
sAtr.nLength = sizeof(SECURITY_ATTRIBUTES);

That's all?

Shouldn't it be:

SECURITY_ATTRIBUTES sAtr;
memset(&sAttr, 0, sizeof(sAttr));
sAtr.nLength = sizeof(SECURITY_ATTRIBUTES);

and fill out the structure members
0
akalmaniCommented:
I am sorry baiqmz try this it should work because i have tried this out..
CreateDirectory("D:\\temp\\Dir1",NULL);
CreateDirectory("D:\\temp\\Dir1\\Dir2",NULL);
CreateDirectory("D:\\temp\\Dir1\\Dir2\\Dir3",NULL);

It will create 3 directories .
0
baigmzAuthor Commented:
Yes, I tried providing no security attributes and it works. The MSDN isn't clear enough.

Thanks anyway.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.