473,231 Members | 1,782 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,231 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 1556
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Andreas Neudecker | last post by:
Hi. I know you can read the filename of a program as sys.argv. But what about modules? Is there a similar way to find out the file name of a module (called by some other module or program) from...
2
by: Vince | last post by:
I have a very specific problem to solve but I cannot find a data structure for it. I don't know if I am posting on the good newsgroup but I cannot find a software.design group. I would like to...
2
by: Joerg Battermann | last post by:
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...
34
by: priyanka | last post by:
Hi, I was wondering if we could parse or do something in the executable( whose source language was C). How can I use some scripting language like perl/python to find out the information about...
18
by: vermarajeev | last post by:
Hello everybody, This is my second query in this post. Firstly thankx to Banfa, for helping me solve my first query. Here is the code which I have written. #include<iostream>...
4
by: Dameon | last post by:
Hi All, I have a process where I'd like to search the contents of a file(in a dir) for all occurences (or the count of) of a given string. My goal is to focus more on performance, as some of the...
2
by: karinmorena | last post by:
I'm having 4 errors, I'm very new at this and I would appreciate your input. The error I get is: Week5MortgageGUI.java:151:cannot find symbol symbol: method allInterest(double,double,double)...
16
by: vizzz | last post by:
Hi there, i need to find an hex pattern like 0x650A1010 in a binary file. i can make a small algorithm that fetch all the file for the match, but this file is huge, and i'm scared about...
4
by: =?Utf-8?B?VG9yZW4gVmFsb25l?= | last post by:
Was editing code, am getting the following errors } expected Type or namespace definition, or end-of-file expected Eyes crossed cannot find code below! using System; using...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

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.