Solved

mkdir

Posted on 2007-04-04
6
537 Views
Last Modified: 2008-02-26
hi
want to create a folder using c++.
compiler visual c++ 6.0

~marchent~
0
Comment
Question by:marchent
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 8

Accepted Solution

by:
deepu chandran earned 150 total points
ID: 18850876
hi,

Here is the example for this,

#include <direct.h>
#include <stdlib.h>
#include <stdio.h>

void main( void )
{
   if( _mkdir( "\\testtmp" ) == 0 )
   {
      printf( "Directory '\\testtmp' was successfully created\n" );
      system( "dir \\testtmp" );
      if( _rmdir( "\\testtmp" ) == 0 )
        printf( "Directory '\\testtmp' was successfully removed\n"  );
      else
         printf( "Problem removing directory '\\testtmp'\n" );
   }
   else
      printf( "Problem creating directory '\\testtmp'\n" );
}


Deepu
0
 
LVL 13

Author Comment

by:marchent
ID: 18851010
hi,
it works. but what if i want to do create the folder at the same directory where my .exe is?
0
 
LVL 6

Assisted Solution

by:bijopuli
bijopuli earned 150 total points
ID: 18851045
Hi

#include <windows.h>

CreateDirectory (char *DirName, SECURITY_ATTRIBUTES Attribs);


Call this function like this:

CreateDirectory ("MyFile.txt", NULL);

If the function succeeds returns non-zero otherwise NULL.

Regards
Bijo.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 6

Assisted Solution

by:_iskywalker_
_iskywalker_ earned 150 total points
ID: 18851052
#include <direct.h>
#include <stdlib.h>
#include <stdio.h>

int main( void )
{
   char* buffer;

   // Get the current working directory:
   if( (buffer = _getcwd( NULL, 0 )) == NULL )
      perror( "_getcwd error" );
   else
   {
      printf( "%s \nLength: %d\n", buffer, strlen(buffer) );
      free(buffer);
   }
}
0
 
LVL 6

Expert Comment

by:bijopuli
ID: 18851084
CreateDirectory ("MyDir", NULL);
0
 
LVL 6

Expert Comment

by:bijopuli
ID: 18851090
that single line of code gives ur directory in the application path..
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question