×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

File Streams

File Streams

File Streams

(OP)
HI
How do i check in C++ whether a directory exists or not?
If exists does it have write permissions?
How do I do the above checks? Some sample code will helpful

Thanx in Advance

RE: File Streams

Which compiler are you using? BCB has a library called FileCtrl which has a function called DirectoryExists. I assume Borland C++ 5.5 has it, too.

James P. Cottingham
www.ivcusa.com

RE: File Streams

See if you have the io.h file in your libraries. In this is a function called access. It take the form of int access(const char *filename, intamode). Amode can be one of the following:
06 - Check for read and write permission
04 - Check for read permission
02 - Check for write permission
01 - (ignored but supposed to be for execute)
00 - Check for existence of file.

If the filename is a directory name, access simply returns whether the directory exists or not.

The integer returned can be 0 if the requested amode is true, or -1 for false. The following example comes from my Borland C++ 5.02 help file.

 #include <stdio.h>
 #include <io.h>

 int file_exists(char *filename);

 int main(void)
 {
    printf("Does NOTEXIST.FIL exist: %s\n",
      file_exists("NOTEXISTS.FIL") ? "YES" : "NO");
    return 0;
 }

 int file_exists(char *filename)
 {
   return (access(filename, 0) == 0);
 }


Sorry it took so long.

James P. Cottingham
www.ivcusa.com

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close