CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 3 FirstFirst 123 LastLast
Results 16 to 30 of 31
  1. #16
    Join Date
    Jun 2002
    Location
    Moscow, Russia.
    Posts
    2,176

    Re: how to create directory in c++

    Quote Originally Posted by bhas_purk
    i had to create directories in windows using VC++
    I can get CreateDirectory to work only when the path is like " c:/face"
    If I give "c:/face/images" it doesnt create the folder, not even face, any help would be appreciated.

    if I have c:/face created then it creates ./image also :?
    You'll need to iteratively create enclosed folders: first c:/face, then c:/face/images.
    "Programs must be written for people to read, and only incidentally for machines to execute."

  2. #17
    Join Date
    Jul 2008
    Posts
    3

    Re: how to create directory in c++

    CreateDirectory() can only be used to create the final directory, if one or more intermediate directories do not exist, CreateDirectory() will fail with an error 3.

    You may use SHCreateDirectoryEx() indeed, this fuction will generate a folder and its sub folders.

  3. #18
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,637

    Re: how to create directory in c++

    The thread that won't die.

  4. #19
    Join Date
    Jan 2009
    Posts
    1

    Re: how to create directory in c++

    lol, it never will
    Last edited by l034n; January 7th, 2009 at 11:26 AM.

  5. #20
    Join Date
    Aug 2010
    Posts
    1

    Cool Re: how to create directory in c++

    I know this is an old thread but this solution will work in both Windows and Linux.

    char sysText[256];
    sprintf( systext, "mkdir %s", path ); // path is a char * to the string representing the directory you want to create
    system( systext );

  6. #21
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,675

    Re: how to create directory in c++

    Quote Originally Posted by whittenrob View Post
    Code:
    char sysText[256];
    sprintf( systext, "mkdir %s", path );  // path is a char * to the string representing the directory you want to create
    system( systext );
    Why that complicated? As already has been posted in this thread (long time ago), the C++ runtime has a mkdir() function on both *nix and Windows.

  7. #22
    Join Date
    Jan 2006
    Posts
    8

    Re: how to create directory in c++

    I am having some difficult times with this too.

    my code in MS Visual C++ 6.0 looks like

    char dirname[FILENAME_MAX] = {"c:\\new_directory\\"};
    int erc;
    erc = mkdir(dirname);

    so far it works fine.
    .....................................

    I am trying to do the same thing using MS Visual C++ 2010 Express

    the same set of instructions are not accepted, is there something I should add/change?

    thanks in advance

  8. #23
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    Re: how to create directory in c++

    Try _mkdir().

  9. #24
    Join Date
    Jan 2006
    Posts
    8

    Re: how to create directory in c++

    I got back this

    '_mkdir': identifier not found

    could you please help me with the include file name, maybe it has changed ....

  10. #25
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    Re: how to create directory in c++


  11. #26
    Join Date
    Aug 2011
    Posts
    3

    Resolved Re: how to create directory in c++

    You can create directory in windows by using dis code ...................... jst pass da name of folder using char array

    #include<iostream>
    using namespace std;
    void main()
    {
    system("mkdir D:foldername");

    }

  12. #27
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,637

    Re: how to create directory in c++

    Quote Originally Posted by [email protected] View Post
    You can create directory in windows by using dis code ...................... jst pass da name of folder using char array

    #include<iostream>
    using namespace std;
    void main()
    {
    system("mkdir D:foldername");

    }

  13. #28
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    Re: how to create directory in c++

    Quote Originally Posted by GCDEF View Post
    Quote Originally Posted by [email protected] View Post
    You can create directory in windows by using dis code ...................... jst pass da name of folder using char array

    #include<iostream>
    using namespace std;
    void main()
    {
    system("mkdir D:foldername");

    }
    Well, [email protected] seems to be not a reader, he/she is a writer!
    Victor Nijegorodov

  14. #29
    Join Date
    Aug 2011
    Posts
    3

    Thumbs down Re: how to create directory in c++

    Quote Originally Posted by VictorN View Post
    Well, [email protected] seems to be not a reader, he/she is a writer!
    i m reader too
    i m nt a linux user
    and btw system("dos comands");
    alows u to copy , move , and delete dir even so it a wide way open to use MS-DOS comands

  15. #30
    Join Date
    Aug 2011
    Posts
    3

    Re: how to create directory in c++

    Quote Originally Posted by exsan View Post
    I got back this

    '_mkdir': identifier not found

    could you please help me with the include file name, maybe it has changed ....
    its works like
    void main (){

    system("mkdir C:\\folder name");

    }
    u can pass folder name wid char array

Page 2 of 3 FirstFirst 123 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured