Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5991155
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T23:20:48+00:00 2026-05-22T23:20:48+00:00

Question In a Windows C application I want to validate a parameter passed into

  • 0

Question

In a Windows C application I want to validate a parameter passed into a function to ensure that the specified path exists.*

How do you check if a directory exists on Windows in C?

*I understand that you can get into race conditions where between the time you check for the existance and the time you use the path that it no longer exists, but I can deal with that.

Additional Background

Knowing explicitly that a directory does or does not exist can get tricky when permissions come into play. It’s possible that in attempting to determine if the directory exists, the process doesn’t have permissions to access the directory or a parent directory. This is OK for my needs. If the directory doesn’t exist OR I can’t access it, both are treated as an invalid path failure in my application, so I don’t need to differentiate. (Virtual) bonus points if your solution provides for this distinction.

Any solution in the C language, C runtime library, or Win32 API is fine, but ideally I’d like to stick to libraries that are commonly loaded (e.g. kernel32, user32, etc.) and avoid solutions that involve loading non-standard libraries (like PathFileExists in Shlwapi.dll). Again, (Virtual) bonus points if your solution is cross-platform.

Related

How can we check if a file Exists or not using Win32 program?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T23:20:48+00:00Added an answer on May 22, 2026 at 11:20 pm

    Do something like this:

    BOOL DirectoryExists(LPCTSTR szPath)
    {
      DWORD dwAttrib = GetFileAttributes(szPath);
    
      return (dwAttrib != INVALID_FILE_ATTRIBUTES && 
             (dwAttrib & FILE_ATTRIBUTE_DIRECTORY));
    }
    

    The GetFileAttributes() method is included in Kernel32.dll.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on an application for Windows Phone platform. Run into a question.
I want to do exactly the same as in this question : Windows file
Update: Check out this follow-up question: Gem Update on Windows - is it broken?
Greetings! Anyway, My question, If you want to experiment developing for a Windows Mobile
I want to present you my windows forms application scenario: I want to create
I have a WCF service that is hosted in a windows application. The service
I have a simple textbox on my Windows Phone 7 application. I want to
That's a mouthful of a question but basically I want to know if I
I am working on a Windows Form Application and I want to allow the
I'm developing a Windows Phone application. I make the question here because I think

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.