#1
  1. Cast down
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Location
    Sweden
    Posts
    321
    Rep Power
    12

    Checking if a directory exists (windows/C)


    Is their an API to do this?
  2. #2
  3. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,641
    Rep Power
    4247
    http://msdn.microsoft.com/library/de...dfirstfile.asp
    You can use it to check if a directory exists as well. FindFirstFile() will return INVALID_HANDLE_VALUE, if the directory does not exist.
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
  4. #3
  5. Cast down
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Location
    Sweden
    Posts
    321
    Rep Power
    12
    I'v had trouble with it.
    User types directory in a Editbox,

    Code:
    Directory=GetText(hWnd,IDC_EDIT1); 
    
    if(FindFirstFile(Directory,NULL)==INVALID_HANDLE_VALUE)
        Ebox("NOT HERE"); 
    else
        Ebox("HERE");
    If the dir does not exist, I get "NOT HERE", else it crashes. In my program, I have it check the end of what the user put for a "\" or "/" and add a slash if their is none, I do this AFTER checking if dir exists.


    update: Ebox is just MessageBox(), GetText is SendMessage wm gettext, directory is char* and holds the text + null terminator.
  6. #4
  7. Cast down
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Location
    Sweden
    Posts
    321
    Rep Power
    12
    Dumb mistake, Ok thanks, it works. It needs a win23 finddata, can't be null.

IMN logo majestic logo threadwatch logo seochat tools logo