Thread: Creating a new directory

  1. #1
    Registered User
    Join Date
    Oct 2005
    Location
    Brasil
    Posts
    220

    Creating a new directory

    in the following code:
    Code:
    ofstream a_file("C:\\Documents and Setings\\Desktop\\Data")
    if the path doesnt exist what should i do to the program create it?

  2. #2
    Registered User
    Join Date
    Feb 2003
    Posts
    596
    Quote Originally Posted by Scarvenger
    in the following code:
    Code:
    ofstream a_file("C:\\Documents and Setings\\Desktop\\Data")
    if the path doesnt exist what should i do to the program create it?
    Fix the spelling?

    "C:\\Documents and Settings\\Desktop\\Data"

  3. #3
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    call win32 api CreateDirectory(), or mkdir(), or SHCreateDirectoryEx(). see MSDN for description of all these functions.

  4. #4
    Banned
    Join Date
    Oct 2005
    Posts
    4
    If your system is POSIX compliant then you can use mkdir() if it isn't just take the shortcut like I do:

    Code:
    #include <cstdlib>
    
    std::system("mkdir \"some folder\"");
    When in doubt... use system().

  5. #5
    Computer guy
    Join Date
    Sep 2005
    Location
    I'm lost!!!
    Posts
    200
    Use this:
    Code:
    #include <windows.h>         //need this header
    
    void main()
    {
          CreateDirectory("Path name", NULL);
    }
    Hello, testing testing. Everthing is running perfectly...for now

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Profiler Valgrind
    By afflictedd2 in forum C++ Programming
    Replies: 4
    Last Post: 07-18-2008, 09:38 AM
  2. Couple errors please help :-D
    By JJJIrish05 in forum C Programming
    Replies: 9
    Last Post: 03-06-2008, 02:54 AM
  3. Replies: 9
    Last Post: 03-03-2006, 10:11 PM
  4. MFC: How do you check if a directory exists before creating?
    By BrianK in forum Windows Programming
    Replies: 5
    Last Post: 07-06-2004, 01:09 AM
  5. Creating a file in a certain directory
    By bc17 in forum C++ Programming
    Replies: 10
    Last Post: 11-24-2002, 12:20 PM