Detect existing files?
Stephan Schulz
schulz at informatik.tu-muenchen.de
Wed May 2 13:40:20 EDT 2001
Hi again,
thanks to Brian and everyone else who pointed me to os.path.* almost
instantly - I don't think that more than 5 minutes passed between my
question and the first reply.
On Wed, May 02, 2001 at 09:57:09AM -0700, Brian Quinlan wrote:
>
> Stephan Schulz wrote:
> > Now my question: Is there a simple way to detect an existing file?
> >
> > open() seems to raise an error if the file does not exist, which is
> > kind of overkill for me.
>
> Take a glance at os.access(). Simple usage:
>
> import os
> os.access( r'c:\test.txt', os.F_OK )
>
> But if I needed to access the file anyway, I would just use open() and
> handle the exception.
I need the opposite case - if the file exists, I leave it alone,
otherwise I create it. Moreover, I'm not yet into exception handling.
Bye,
Stephan
--
-------------------------- It can be done! ---------------------------------
Please email me as schulz at informatik.tu-muenchen.de (Stephan Schulz)
----------------------------------------------------------------------------
More information about the Python-list
mailing list