473,473 Members | 1,823 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

is a file open ?

for root, dirs, files in os.walk(path):
for file in files:
# ¿ is opened ?
Best regards

Luis
Jul 21 '05 #1
6 1427
luis wrote:
for root, dirs, files in os.walk(path):
for file in files:
# ¿ is opened ?


¡ rtfm ! "files" is a list of fileNAMEs -- i.e. strings.
¿ How could you possibly imagine that your sample code would open a
file? What a design-nonsense that would be: instant complaints from folk
who wanted to do some further selection before opening (if they ever
wanted to open the files at all).
¿ Did you contemplate *trying* this code to see what happened ?
¡ Don't use "file" as a name; it shadows the built-in file function !
Jul 21 '05 #2
luis wrote:
for root, dirs, files in os.walk(path):
for file in files:
# ¿ is opened ?


On Linux and some other Unixes, you can probably read the /proc filesystem.

On Windows, you'll probably get the quickest result by running
handle.exe (http://www.sysinternals.com/Utilities/Handle.html).

Either way, the information you'll get is restricted by your permissions.

Either information will get stale really fast, so it's not suitable if
your task is something like 'can I backup this directory or is someone
writing to a file?'

Daniel
Jul 21 '05 #3
Daniel Dittmar wrote:
luis wrote:
for root, dirs, files in os.walk(path):
for file in files:
# ¿ is opened ?

On Linux and some other Unixes, you can probably read the /proc filesystem.

On Windows, you'll probably get the quickest result by running
handle.exe (http://www.sysinternals.com/Utilities/Handle.html).

Either way, the information you'll get is restricted by your permissions.

Either information will get stale really fast, so it's not suitable if
your task is something like 'can I backup this directory or is someone
writing to a file?'


If that's what the OP had in mind, the question might have been better
phrased as "given the path to a file, how can I tell if it is currently
opened by another process/thread", and better directed to OS-specifc
newsgroup(s).

Jul 21 '05 #4
John Machin wrote:
Daniel Dittmar wrote:
luis wrote:
for root, dirs, files in os.walk(path):
for file in files:
# ¿ is opened ?


On Linux and some other Unixes, you can probably read the /proc
filesystem.

On Windows, you'll probably get the quickest result by running
handle.exe (http://www.sysinternals.com/Utilities/Handle.html).

Either way, the information you'll get is restricted by your permissions.

Either information will get stale really fast, so it's not suitable if
your task is something like 'can I backup this directory or is someone
writing to a file?'

If that's what the OP had in mind, the question might have been better
phrased as "given the path to a file, how can I tell if it is currently
opened by another process/thread", and better directed to OS-specifc
newsgroup(s).

there is a specific python function ?
Jul 21 '05 #5
John Machin wrote:
Daniel Dittmar wrote:
luis wrote:
for root, dirs, files in os.walk(path):
for file in files:
# ¿ is opened ?


On Linux and some other Unixes, you can probably read the /proc
filesystem.

On Windows, you'll probably get the quickest result by running
handle.exe (http://www.sysinternals.com/Utilities/Handle.html).

Either way, the information you'll get is restricted by your permissions.

Either information will get stale really fast, so it's not suitable if
your task is something like 'can I backup this directory or is someone
writing to a file?'

If that's what the OP had in mind, the question might have been better
phrased as "given the path to a file, how can I tell if it is currently
opened by another process/thread", and better directed to OS-specifc
newsgroup(s).

there is a specific python function ?
Jul 21 '05 #6
luis wrote:
John Machin wrote:
Daniel Dittmar wrote:
luis wrote:

for root, dirs, files in os.walk(path):
for file in files:
# ¿ is opened ?


On Linux and some other Unixes, you can probably read the /proc
filesystem.

On Windows, you'll probably get the quickest result by running
handle.exe (http://www.sysinternals.com/Utilities/Handle.html).

Either way, the information you'll get is restricted by your
permissions.

Either information will get stale really fast, so it's not suitable
if your task is something like 'can I backup this directory or is
someone writing to a file?'


If that's what the OP had in mind, the question might have been better
phrased as "given the path to a file, how can I tell if it is
currently opened by another process/thread", and better directed to
OS-specifc newsgroup(s).

there is a specific python function ?


If you mean "is there a Python function that given a filename, returns
an indication of whether that file has been opened by another
process/thread, portably across different operating systems?" then the
answer is NO. This is what I meant by "the question might have been ...
better directed to OS-specifc newsgroup(s)". That is what you should
have inferred from Daniel's reply "On Linux ... probably ... On Windows
.... probably...".

If you mean something else, you might like to try rephrasing your question.
Jul 21 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: Chuck Amadi | last post by:
Sorry to bovver you again (again) here's script. I still can't see why the get_payload() doesn't produce the plain text message body of an emails in the testwwws users mailbox. As you can see I...
3
by: Abhas | last post by:
> > Hi, this is Abhas, > > I had made a video library program in C++, but was facing a problem. > > After entering 12 movies, i cannot enter any more movies. > > Something gibberish comes instead....
13
by: George | last post by:
Hi, I am re-writing part of my application using C#. This application starts another process which execute a "legacy" program. This legacy program writes to a log file and before it ends, it...
14
by: prasadjoshi124 | last post by:
Hi All, I am writing a small tool which is supposed to fill the filesystem to a specified percent. For, that I need to read how much the file system is full in percent, like the output given...
1
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Many websites have a form or a link you can use to download a file. You click a form button or click...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.