• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 187
  • Last Modified:

Get a Directory

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
chowdry
Asked:
chowdry
  • 3
  • 2
1 Solution
 
nietodCommented:
Use GetFileAttributes()   details follow.
0
 
thresher_sharkCommented:
Use the "access" function.  It does exactly what you want.

Try this:
access ("Directory path goes here", 0);
0
 
thresher_sharkCommented:
But nietod's solution is better.
0
 
nietodCommented:
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
 
nietodCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now