Get a Directory

Posted on 1998-09-15
Last Modified: 2012-05-04
Is it possible to know whether a particular directory is exisying in the system or not? I am using NT 4.0. This is apart from knowing the Current Directory and the System Directory.
Question by:chowdry
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
LVL 22

Accepted Solution

nietod earned 20 total points
ID: 1172758
Use GetFileAttributes()   details follow.

Expert Comment

ID: 1172759
Use the "access" function.  It does exactly what you want.

Try this:
access ("Directory path goes here", 0);

Expert Comment

ID: 1172760
But nietod's solution is better.
LVL 22

Expert Comment

ID: 1172761
Call GetFileAttributes() and specify the path to the directory you are interested in.  If the procedure returns 0xFFFFFFFF, then the path was invalid, and the directory doesn't exist.  If the procedure returns any other value, test to see if the FILE_ATTRIBUTE_DRECTORY bit is set.  If so, the path specifies an existing directory.  If not, the path specifies an existing file.

let me know if you have questions.
LVL 22

Expert Comment

ID: 1172762
The problem with access() is that if the file exists, you can't tell if the file is a directory or a regular file.  That could be important.  For a standard C++ approach, you can use fstat() instead of access() and check the file type.

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question