0

hello,

I am working on a project that involves a bit of directory manipulation. Until now i only had to create create directories as per user input, so till now the commnad mkdir worked fine:
mkdir("c:/test");

But now i have to do some manipulations on the string to get the path.I have run into this problem where mkdir is not crating the directories when i pass a string variable as argumnet.
//str=(assigned something after manipulations);
mkdir(str);

Is there another way i can do this??

Thank you!

4
Contributors
10
Replies
16
Views
4 Years
Discussion Span
Last Post by Moschops
Featured Replies
  • > / worked fine for me actually. Because `/` is not a backslash. `\` is a backslash. `/` is far more portable and as a general rule is preferable to using `\\` Read More

0

its not working. gives me the following error

request for member `c_str' in something not a structure or union

0

Oop. Sorry; my fault! I saw you mention a string and forgot this was C land - I'm so used to a string being a C++ string object and nowadays I never use the term in C.

Can you give some sample code that doesn't work?

Edited by Moschops

0

Another hint: mkdir() only works on one directory at a time. You have to call mkdir() for each new directory in the directory hierarcy. If you want to create a directory "c:\one\two\three" then call mkdir("c:\one"), mkdir("c:\one\two") and finally mkdir("c:\one\two\three")

Edited by Ancient Dragon

0

Thanks a lot Ancient Dragon. i was trying to create 3 directories at a time. Had to split it up with a for loop to make 1 directory at a time.

Thank you for the inputs, Moschops.

0

Yes, like this: mkdir("c:\\one\\two\\three"). (you actully need four of them to post here because the editor removes two of them. That is escaping the escape character \)

Edited by Ancient Dragon

0

/ worked fine for me actually.

strcpy(dirname,"c:/YeSQL/");
mkdir(dirname);
1

/ worked fine for me actually.

Because / is not a backslash. \ is a backslash.

/ is far more portable and as a general rule is preferable to using \\

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.