Solved

mkdir

Posted on 2007-04-04
6
523 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
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 member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

760 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now