Thread: How to write programt to create folder?

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    68

    How to write programt to create folder?

    If I want to create forder "3" like this c:\3\
    How to write program to do that?

  2. #2
    Banned nickname_changed's Avatar
    Join Date
    Feb 2003
    Location
    Australia
    Posts
    986
    There are a few different ways, I think i remember a function in a windows header somewhere that did it (CreateDir or something I think) but you could always use
    Code:
    #include <stdlib.h>
    ..
    system("mkdir foldername");
    (if mkdir is the right command for making a folder in windows, I forget).

    PS: You would do better to search windows header files though anyway, I'd start at wincon.h, I think its in there.

    ~ Paul

  3. #3
    Registered User Dev's Avatar
    Join Date
    Mar 2003
    Posts
    59
    I think there are standard routines also available for creating folders.

    Try searching the documentation of your compiler.

  4. #4
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >I think there are standard routines also available for creating folders.
    No, but there are usually non-standard compiler libraries that do this. However, it appears that you're using Windows, so you can turn to the Win32 API with the CreateDirectory function:
    Code:
    #include <iostream>
    #include <string>
    #include <windows.h>
    
    int main()
    {
      std::string folder_name;
    
      std::cout<<"Enter a folder name to create: ";
      std::getline ( std::cin, folder_name );
    
      if ( CreateDirectory ( folder_name.c_str(), NULL ) != 0 )
        std::cout<<"Folder created successfully"<<std::endl;
    }
    -Prelude
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. I need the code of few programs in c++.plzzzzz help...plzzz
    By NAVINKR20 in forum C++ Programming
    Replies: 1
    Last Post: 05-08-2009, 09:13 AM
  2. most efficient way to write filestream objects?
    By darsunt in forum C++ Programming
    Replies: 3
    Last Post: 01-26-2009, 05:17 PM
  3. How to write a program
    By Tashfique in forum C++ Programming
    Replies: 4
    Last Post: 10-17-2008, 11:28 AM
  4. Game Programming FAQ
    By TechWins in forum Game Programming
    Replies: 5
    Last Post: 09-29-2004, 02:00 AM
  5. How to create a folder
    By andreas_nordman in forum C++ Programming
    Replies: 1
    Last Post: 06-14-2004, 06:25 AM