CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    May 2007
    Posts
    3

    Arrow How to check directory's presence?

    Hi,

    I need to see if a particular directory is present or not, at the specified path.
    For a file we can do it using fopen() return value but what for a directory (for all platforms)?

    --Virendra--
    Last edited by vnyelurkar; May 10th, 2007 at 05:42 AM.

  2. #2
    Join Date
    May 2002
    Posts
    10,943

    Re: How to check directory's presence?

    What language are you doing this in...PHP? If so, you can use file_exists. It checks for files or directories.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  3. #3
    Join Date
    May 2007
    Posts
    3

    Arrow Re: How to check directory's presence?

    PeejAvery,

    I am doing this through C++. Here, I want to know if the directory already exists, before calling CreateDirectory() API.

    Thanks,
    --Virendra--

  4. #4
    Join Date
    Feb 2005
    Location
    Normandy in France
    Posts
    4,590

    Re: How to check directory's presence?

    Use CreateFile with dwDesiredAccess==0 and dwCreationDistribution==OPEN_EXISTING.
    CreateFile can be used to "open directories".
    It should fail if the directory doesn't exist.
    "inherit to be reused by code that uses the base class, not to reuse base class code", Sutter and Alexandrescu, C++ Coding Standards.
    Club of lovers of the C++ typecasts cute syntax: Only recorded member.

    Out of memory happens! Handle it properly!
    Say no to g_new()!

  5. #5
    Join Date
    May 2007
    Posts
    3

    Re: How to check directory's presence?

    Ya, this one is better solution.
    Thanks a lot........

  6. #6
    Join Date
    May 2002
    Posts
    10,943

    Re: How to check directory's presence?

    Quote Originally Posted by vnyelurkar
    I am doing this through C++.
    Then this belongs in the C++ forum. I would have never been confused if it had been there to start. Glad your problem was solved.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  7. #7
    Join Date
    Dec 2001
    Posts
    6,332

    Re: How to check directory's presence?

    [ Moved Thread ]
    Please remember to rate the posts and threads that you find useful.
    How can something be both new and improved at the same time?

  8. #8
    Join Date
    May 2005
    Posts
    4,954

    Re: How to check directory's presence?

    Look at ::PathIsDirectory().

    Cheers
    If a post helped you dont forget to "Rate This Post"

    My Article: Capturing Windows Regardless of Their Z-Order

    Cheers

  9. #9
    Join Date
    Sep 2004
    Location
    Italy
    Posts
    389

    Re: How to check directory's presence?

    The easier one: GetFileAttributes() == FILE_ATTRIBUTE_DIRECTORY.

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