Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

mkdir

Posted on 2007-04-04
6
Medium Priority
?
540 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 600 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 600 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 6

Assisted Solution

by:_iskywalker_
_iskywalker_ earned 600 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
Suggested Courses

618 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