471,355 Members | 1,631 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,355 software developers and data experts.

How to find out whether a file cannot be read?

Hello there,

I was wondering how I can check whether I am allowed to read a certain file
or not? Some of e.g. XP's files are not readable, not even by the Administrator,
and when trying to open a file for reading, it throws an exception (e.g.:
{"The process cannot access the file \"C:\\Documents and Settings\\Joerg\\Local
Settings\\Application Data\\Lookout Software\\Lookout\\Data.Outlook\\Log
Files\\log.txt\" because it is being used by another process." })

How can I check whether I am allowed to read/open files?
Best regards / MfG,
--
Joerg Battermann
jb@justBE.com
http://www.justBE.com - blog: http://blog.justBE.com
*
PGP-KeyID: 0x77007DA6
PGP-Fingerprint: 0461 F2EC 53EB CEBE 6B73*8EEC 64AD 0606 7700 7DA6
Jul 21 '05 #1
2 1476
First, this does not mean that you do not have permissions to read the file,
but rather some process has already opened it for exclusive use. The file
system is preventing more then one process from accessing the file for the
sake of concurrency.

Second, I think the exception is good enough. Is there some reason that you
could not just trap the exception? Seems like a pretty good way of
determining if you can open a file.
"Joerg Battermann" <jb@justbe.com> wrote in message
news:38**********************@news.mediascape.de.. .
Hello there,

I was wondering how I can check whether I am allowed to read a certain file or not? Some of e.g. XP's files are not readable, not even by the Administrator, and when trying to open a file for reading, it throws an exception (e.g.:
{"The process cannot access the file \"C:\\Documents and Settings\\Joerg\\Local Settings\\Application Data\\Lookout Software\\Lookout\\Data.Outlook\\Log
Files\\log.txt\" because it is being used by another process." })

How can I check whether I am allowed to read/open files?
Best regards / MfG,
--
Joerg Battermann
jb@justBE.com
http://www.justBE.com - blog: http://blog.justBE.com

PGP-KeyID: 0x77007DA6
PGP-Fingerprint: 0461 F2EC 53EB CEBE 6B73 8EEC 64AD 0606 7700 7DA6

Jul 21 '05 #2
Joerg,

In addition to Peter.

You answered it yourself use a Try Catch to get the exception.

That is what Try Catch exceptions are made for, getting the things you can
not get inside your program because it happens outside of that.

An often asked question is "how can I go on when it is locked?. You can use
classic goto style code, in my opinion is it than better to set it in a loop
where you test if it is going, while you set a
threading.thread.sleep(seconds) in that and eventualy a messagebox when it
is taking to long to let the user abort..

I hope this helps?

Cor
Jul 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Andreas Neudecker | last post: by
2 posts views Thread by Joerg Battermann | last post: by
4 posts views Thread by Dameon | last post: by
2 posts views Thread by karinmorena | last post: by
16 posts views Thread by vizzz | last post: by
4 posts views Thread by =?Utf-8?B?VG9yZW4gVmFsb25l?= | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.