2007年9月19日星期三

What is the code in C++ for MKDIR?

What is the code in C++ for MKDIR?
Jim Morrison
03-15-2001, 04:30 PM
This may stupid question..........I know enough C++ to get me into trouble
so here is my question.

Is there and equivalant sorce code in C++ for the MKDIR command?

jonnin
03-15-2001, 05:24 PM
every os andcompiler has one, but this is portable:
system("mkdir dirname"); from process.h

"Jim Morrison" wrote:
>
>This may stupid question..........I know enough C++ to get me into trouble
>so here is my question.
>
>Is there and equivalant sorce code in C++ for the MKDIR command?

Danny Kalev
03-15-2001, 06:29 PM
try to use the mkdir() function. Most implementations (Unix, Win32)
support it even though it's not part of the ANSI/ISO standard:

#include

int n=mkdir("c://myfiles//mydir");
if(n==0) // mkdir succeeded
....
else // it failed


Jim Morrison wrote:
>
> This may stupid question..........I know enough C++ to get me into trouble
> so here is my question.
>
> Is there and equivalant sorce code in C++ for the MKDIR command?

Marcel
03-16-2001, 09:10 AM
Try e.g.: _mkdir("C:\\ABC\\NAME");

Note: Directory C:\ABC must exist.
Marcel

Appu
03-16-2001, 10:45 AM
Just a small correction...

#include

And also, the return value will be negative(non zero) if the directory already
exists in the specified path...

rgds
Appu
Danny Kalev wrote:
>try to use the mkdir() function. Most implementations (Unix, Win32)
>support it even though it's not part of the ANSI/ISO standard:
>
>#include
>
>int n=mkdir("c://myfiles//mydir");
>if(n==0) // mkdir succeeded
>....
>else // it failed
>
>
>Jim Morrison wrote:
>>
>> This may stupid question..........I know enough C++ to get me into trouble
>> so here is my question.
>>
>> Is there and equivalant sorce code in C++ for the MKDIR command?

Danny Kalev
03-16-2001, 11:06 PM
Appu wrote:
>
> Just a small correction...
>
> #include

Actually, I just checked under Borland C++ Builder. *both*
and are supported ( is a different story...). It seems
like simply #include .

>
> And also, the return value will be negative(non zero) if the directory already
> exists in the specified path...

Not necessarily. A negative value indicates an error of some sort. To
get the precise error code, one has to check errno after calling mkdir.
The negative value may indicate insufficient permissions for example.

Danny

没有评论: