Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


Get a Directory

Posted on 1998-09-15
Medium Priority
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 60 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses

722 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