Solved

Get a Directory

Posted on 1998-09-15
5
180 Views
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.
0
Comment
Question by:chowdry
  • 3
  • 2
5 Comments
 
LVL 22

Accepted Solution

by:
nietod earned 20 total points
ID: 1172758
Use GetFileAttributes()   details follow.
0
 
LVL 6

Expert Comment

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

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

Expert Comment

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

Expert Comment

by:nietod
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.
0
 
LVL 22

Expert Comment

by:nietod
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.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Handle Exceptions during instantiation 28 416
Template syntax for variable length arrays 9 75
Find Visual Studio Tools 2 103
Issues with C++ Class 19 92
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

809 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