Solved

Get a Directory

Posted on 1998-09-15
5
178 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
Comment Utility
Use GetFileAttributes()   details follow.
0
 
LVL 6

Expert Comment

by:thresher_shark
Comment Utility
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
Comment Utility
But nietod's solution is better.
0
 
LVL 22

Expert Comment

by:nietod
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
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…
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 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…

762 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now