How to check a directory is exist or not?

This is a discussion on How to check a directory is exist or not? within the C++ Programming forums, part of the General Programming Boards category; Please tell me how to check a directory is exist or not? If it not exist, then how to create? ...

  1. #1
    Unregistered
    Guest

    Lightbulb How to check a directory is exist or not?

    Please tell me how to check a directory is exist or not? If it not exist, then how to create?

    Thanks.

    qi1996@lycos.com

  2. #2
    Registered User
    Join Date
    Dec 2001
    Posts
    206
    Code:
    #include <iostream.h>
    #include <process.h>
    #include <stdio.h>
    #include <conio.h>
    #include <string.h>
    
    void main()
    {
    char path[1024], *MakeDir;
    
    cout<<"\nWhat folder do you wish to check/create?\n";
    cin >> path;
    
    int length1 = strlen("mkdir ");
    int length2 = strlen(path);
    MakeDir = new char [length1 + length2 + 1];
    strcpy(MakeDir, "mkdir ");
    strcat(MakeDir, path);
    
    system(MakeDir);
    
    if(!MakeDir)
    {
        printf("This folder exists.");
    }
    else
    {
        printf("There was no directory. A directory has been created.");
    }
    getch();
    }

  3. #3
    Registered User
    Join Date
    Dec 2001
    Posts
    206
    That one messes up a bit, here, use this one instead :
    Code:
    #include <iostream.h>
    #include <process.h>
    #include <stdio.h>
    #include <conio.h>
    #include <string.h>
    
    void main()
    {
    char path[1024], *MakeDir;
    
    cout<<"\nWhat folder do you wish to check/create?\n";
    cin >> path;
    
    int length1 = strlen("mkdir ");
    int length2 = strlen(path);
    MakeDir = new char [length1 + length2 + 1];
    strcpy(MakeDir, "mkdir ");
    strcat(MakeDir, path);
    
    system(MakeDir);
    
    if(!MakeDir)
    {
        //Let DOS handle it
    }
    else
    {
        printf("There was no directory. A directory has been created.");
    }
    getch();
    }

  4. #4
    Registered User
    Join Date
    Dec 2001
    Posts
    206

    Angry

    well i spend my time coding a great script for you that WORKS and u go and leave me without a simple "thank you"??? well im never helping u again

  5. #5
    Registered User biosx's Avatar
    Join Date
    Aug 2001
    Posts
    230
    You think he hasn't look at it yet?

    You coded a program, not a script.

    A script is what you give the actors, a program is what you give the audience.

  6. #6
    Registered User
    Join Date
    Dec 2001
    Posts
    206
    r u saying i did better or worse than a script? lol

    u confuse me.

  7. #7
    Unregistered
    Guest

    Sorry..

    Sorry about thank u late. I really appreciate your program.

    I am a beginninger of c++ programming. I expect your further help.

    Thanks a lot.

    Oh, If I want to check a open a file under a directory on the VC platform, the following statement is correct or not?

    fstream file("temp\aa.dat", ios:ut | ios::binary);


    Scott

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. BN_CLICKED, change button style
    By bennyandthejets in forum Windows Programming
    Replies: 13
    Last Post: 07-06-2010, 12:42 AM
  2. Profiler Valgrind
    By afflictedd2 in forum C++ Programming
    Replies: 4
    Last Post: 07-18-2008, 10:38 AM
  3. Check directory program is run from?
    By willc0de4food in forum C Programming
    Replies: 10
    Last Post: 06-29-2005, 03:36 AM
  4. spell check in C using a dictionary file
    By goron350 in forum C Programming
    Replies: 10
    Last Post: 11-25-2004, 06:44 PM
  5. check my code ( if statement, file existance )
    By Shadow in forum C Programming
    Replies: 1
    Last Post: 10-04-2001, 12:13 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21