Solved

mkdir

Posted on 2007-04-04
6
531 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
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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
C++ standard library based binary archive format 6 104
Least Squares Curve Fitting 4 99
No module found pypyodbc, 3 33
Adding items to a C# list incrementally 5 33
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
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 be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

831 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