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 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.
--
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?)
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)
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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...
|
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...
|
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;...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
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...
|
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...
|
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)...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
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....
|
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
|
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...
| |