Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Get a Directory

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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
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 learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
Suggested Courses

926 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