How to find out whether a file cannot be read?

  • Thread starter Thread starter Joerg Battermann
  • Start date Start date
J

Joerg Battermann

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
(e-mail address removed)
http://www.justBE.com - blog: http://blog.justBE.com
 
PGP-KeyID: 0x77007DA6
PGP-Fingerprint: 0461 F2EC 53EB CEBE 6B73 8EEC 64AD 0606 7700 7DA6
 
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,

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
 
Back
Top