Thread: Create folders?

  1. #1
    Registered User
    Join Date
    Oct 2004
    Posts
    4

    Create folders?

    Can I make C++ make a folder using the I/O method?. Also in the code "ofstream a_file" is "a_file" a C++ command, like could I call it "sdjs_file" if I wanted?

  2. #2
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    a_file is just the name of he ofstream object. You can call it whatever you want (assuming it fits in the rules for variable names and it isn't already in use or a reserved word. "ofstream a_file" just creates an object called a_file that is of type ofstream, and then you can use that object to work with files in a purely output capacity.

    I've never seen a folder made using File I/O, but I don't know if can or not. My guess is that it's OS dependant, and you'll probably have to use the system function (cstdlib / stdlib.h) to do it. system() is often advised against for a variety of reasons, but under the circumstances I don't think it's a huge problem here.

  3. #3
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    >Can I make C++ make a folder using the I/O method?
    You can make one using the function mkdir(). I don't think it's standard, but most compilers have it.
    Code:
    #include <dir.h>
    #include <iostream>
    
    int main()
    {
       if (mkdir("\\dir\\subdir") != 0)
       {
          std::cout << "Could not make dir." << std::endl;
          return 1;
       }
       std::cout << "Directory created." << std::endl;
       
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Can't create child windows
    By OnionKnight in forum Windows Programming
    Replies: 4
    Last Post: 04-10-2011, 04:13 PM
  2. Create a file from c++ program
    By Dan17 in forum C++ Programming
    Replies: 2
    Last Post: 05-08-2006, 04:25 PM
  3. Button handler
    By Nephiroth in forum Windows Programming
    Replies: 8
    Last Post: 03-12-2006, 06:23 AM
  4. How to create a file association program?
    By eShain in forum Windows Programming
    Replies: 1
    Last Post: 03-06-2006, 12:15 PM
  5. How to Create reference to an array in C++
    By shiv_tech_quest in forum C++ Programming
    Replies: 2
    Last Post: 12-20-2002, 10:01 AM