#1
  1. No Profile Picture
    Senior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2001
    Posts
    42
    Rep Power
    0

    File not found vs. Can not read file


    when opening a file, I need to distinguish between file not found and a file that cannot be read to output proper error messages.

    for file not found I am using if (file.fail())
    But how can I detect whether a file cannot be read? For example this being it has no read permissions

    thanks.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Oct 2000
    Location
    Back in the real world.
    Posts
    5,966
    Rep Power
    190
    hi!

    which os does your program run on? which specific programming language do you use? and what is file.fail()?

    trying to answer your question:
    1. search for "stat()"
    2. you could check if your programming language has a function called "int file_exists(char *filename)" or similar.
    3. you could read the permissions and ownership first from the file and then check the current uid/gid against that. err. the first would fail already for "file not found"... ;)
    4. afaik there should be a function getLastError() or similar where you can read the last error-code. and another function that outputs the osīs default error string for this error.

    can you supply more specific infos please?

IMN logo majestic logo threadwatch logo seochat tools logo