Thread: creating a directory?

  1. #1
    Registered User
    Join Date
    Nov 2005
    Posts
    137

    creating a directory?

    msdn says its as simple as Directory:irectoryCreate(path). but it says you have to be #using a dll and thats not working for me. does anyone know how to do this?

  2. #2
    Registered User Dante Shamest's Avatar
    Join Date
    Apr 2003
    Posts
    970
    That looks like managed C++.

    In plain old C/C++, you can use CreateDirectory.

  3. #3
    Registered User
    Join Date
    Nov 2005
    Posts
    137
    hmm. well i also saw on that site that there was a Directory::Exists() function. i tried just getting rid of the Directory:: but it didn't work. how would i check to see if a directory exists?

  4. #4
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    Use GetFileAttributes(), and see if the return value is FILE_ATTRIBUTE_DIRECTORY.

  5. #5
    Registered User
    Join Date
    Nov 2005
    Posts
    137
    so just scan through the files and see if they are a file_attribute_directory and if it is check to see if its the directory i want?

  6. #6
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    Well I have no idea what you are trying to do here, so I don't know if that idea will work for you.

  7. #7
    Registered User
    Join Date
    Nov 2005
    Posts
    137
    i just want to see if a directory exists in a certain directory. so could i just scan through all the files in that directory and see if any of those files is the directory that i'm looking for?

  8. #8
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    GetFileAttributes takes a path so you don't need to scan all the files. Just pass it the path to the directory you wish to check.

  9. #9
    Registered User
    Join Date
    Nov 2005
    Posts
    137
    hmm. i'm not really getting what everyone is trying to say. i've made a function that works, but i don't know if its the best way. it seems kind of slow.

    PHP Code:
    int directoryExists(string dpathstring dname)
    {
        
    HANDLE hFind;
        
    WIN32_FIND_DATA findData;

        
    dpath += '*';
        
    string fname;

        
    hFind FindFirstFile(dpath.c_str(), &findData);

        while (
    FindNextFile(hFind, &findData))
        {
            
    fname findData.cFileName;

            if (
    fname == dname)
            {
                if (
    findData.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY)
                {
                    
    FindClose(hFind);
                    return (
    1);
                }
            }
        }
        
        
    FindClose(hFind);

        return (
    0);


  10. #10
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    Code:
    int directoryExists(string dpath, string dname) 
    {
       char completePath[MAX_PATH];
       sprintf(completePath,"%s\\%s",dpath,dname);
       if(GetFileAttributes(completePAth) == FILE_ATTRIBUTE_DIRECTORY)
          return 1;
       return 0;
    }

  11. #11
    Registered User
    Join Date
    Nov 2005
    Posts
    137
    works like a charm. thank you very much.

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