473,326 Members | 2,732 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,326 software developers and data experts.

Does this path exist?

I wanted to ask for ways to test whether a path exists. I usually use
os.path.exists(), which does a stat call on the path and returns True
if it succeeds, or False if it fails (catches os.error). But stat
calls don't fail only when a path doesn't exist. I see that, at least
on Windows, the instance of the exception has an attribute 'errno' set
to 2 when it fails because the path doesn't exist. Is it a portable
solution to rely on this (haven't tried it on Linux)? Are there other
ways of testing whether a path exists?

Thanks,
Sebastian
Jun 27 '08 #1
4 2107
s0****@gmail.com wrote:
I wanted to ask for ways to test whether a path exists. I usually use
os.path.exists(), which does a stat call on the path and returns True
if it succeeds, or False if it fails (catches os.error). But stat
calls don't fail only when a path doesn't exist. I see that, at least
on Windows, the instance of the exception has an attribute 'errno' set
to 2 when it fails because the path doesn't exist. Is it a portable
solution to rely on this (haven't tried it on Linux)? Are there other
ways of testing whether a path exists?

Thanks,
Sebastian
"import errno" and see if the exception's errno attribute is set to
errno.ENOENT (which is, yes, 2). It is portable.

If you Google [ENOENT Windows] or whatever, there are some differences
on different platforms, but not many.
--
Jun 27 '08 #2
On May 28, 3:47 am, Matt Nordhoff <mnordh...@mattnordhoff.comwrote:
s0s...@gmail.com wrote:
I wanted to ask for ways to test whether a path exists. I usually use
os.path.exists(), which does a stat call on the path and returns True
if it succeeds, or False if it fails (catches os.error). But stat
calls don't fail only when a path doesn't exist. I see that, at least
on Windows, the instance of the exception has an attribute 'errno' set
to 2 when it fails because the path doesn't exist. Is it a portable
solution to rely on this (haven't tried it on Linux)? Are there other
ways of testing whether a path exists?
Thanks,
Sebastian

"import errno" and see if the exception's errno attribute is set to
errno.ENOENT (which is, yes, 2). It is portable.

If you Google [ENOENT Windows] or whatever, there are some differences
on different platforms, but not many.
Thanks. So if OSError().errno == errno.ENOENT, then it means the path
doesn't exist? (What does "ENOENT" stan for?)
Jun 27 '08 #3
On May 28, 10:59*am, s0s...@gmail.com wrote:
On May 28, 3:47 am, Matt Nordhoff <mnordh...@mattnordhoff.comwrote:
s0s...@gmail.com wrote:
I wanted to ask for ways to test whether a path exists. I usually use
os.path.exists(), which does a stat call on the path and returns True
if it succeeds, or False if it fails (catches os.error). But stat
calls don't fail only when a path doesn't exist. I see that, at least
on Windows, the instance of the exception has an attribute 'errno' set
to 2 when it fails because the path doesn't exist. Is it a portable
solution to rely on this (haven't tried it on Linux)? Are there other
ways of testing whether a path exists?
Thanks,
Sebastian
"import errno" and see if the exception's errno attribute is set to
errno.ENOENT (which is, yes, 2). It is portable.
If you Google [ENOENT Windows] or whatever, there are some differences
on different platforms, but not many.

Thanks. So if OSError().errno == errno.ENOENT, then it means the path
doesn't exist? (What does "ENOENT" stan for?)
http://books.google.co.za/books?id=M...142FEeNI&hl=en

ENOENT - Invalid Entry (file or directory)
Jun 27 '08 #4
On May 28, 4:59 am, s0s...@gmail.com wrote:
On May 28, 3:47 am, Matt Nordhoff <mnordh...@mattnordhoff.comwrote:
....
Thanks. So if OSError().errno == errno.ENOENT, then it means the path
doesn't exist? (What does "ENOENT" stan for?)
I always read it as Error NO ENTry
Jun 27 '08 #5

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

Similar topics

11
by: BoonHead, The Lost Philosopher | last post by:
I think the .NET framework is great! It's nice, clean and logical; in contradiction to the old Microsoft. It only saddens me that the new Microsoft still doesn't under stand there own...
15
by: (Pete Cresswell) | last post by:
I've got a .BAT file that I use for executing various MS Access apps that I wrote way back in the days of 2.0. It's evolved over time, but it still contains a number of possible paths to...
0
by: bob | last post by:
I have a somewhat complex question about how Threading works across the network. Below is the full source code of a program that will list any file modified on myServer. When I run this code from...
1
by: Brad | last post by:
I'm trying to use Active Directory to retrieve information for a user...for display purposes.. I am not using windows authentication or impersonation....I am using a fixed user id and password for...
2
by: Raed Sawalha | last post by:
i have very strange problem in a Directory C:\Images I'm checking if an image is exist then copy it to other folder using following code: if(FilePath.Trim().Length == 0) return String.Empty;...
1
by: Dave | last post by:
I am getting te following error in a ASP.Net app that is running on Win XP Pro (SP2): Server cannot access application directory 'C:\Documents and Settings\dave\My Documents\My Visual Studio...
4
by: Mike | last post by:
Hi, I am looking for function in .Net library that let me know if exist any file if I specified template. Eg: I specify "*.txt" and if any file (1.txt, 2.txt, .. ) exists then I can get True...
20
by: Bob Sanderson | last post by:
This is my code: if (file_exists($Fname)) { echo "<td>$Fname exists</td>"; } else { echo "<td>$Fname does not exist</td>"; } $Fname is the full path to the file I'm trying to verify. When I...
2
ADezii
by: ADezii | last post by:
Many times when writing VBA code, we find the need to work with Files in one form or another. Whatever the process may be, we need to be sure that a File is present in a specified location. One...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.