simple way to touch a file if it does not exist

Giampaolo Rodola' gnewsg at gmail.com
Thu May 22 08:58:19 EDT 2008


On 22 Mag, 11:54, Ken Starks <stra... at lampsacos.demon.co.uk> wrote:
> After os.path.exists, you need to check it _is_ a
> file, and not a directory.
>
>
>
> Giampaolo Rodola' wrote:
> > On 22 Mag, 01:15, Nikhil <mnik... at gmail.com> wrote:
> >> what are the simple ways?
> >> I could think of os.open(), os.exec(touch file)
>
> >> are there any simpler methods?
>
> > Just use os.path.exists to check for file existence and open() as
> > replacement for touch.
>
> >>>> import os
> >>>> if not os.path.exists('file'):
> > ...     open('file', 'w').close()
> > ...
>
> > --- Giampaolo
> >http://code.google.com/p/pyftpdlib/- Nascondi testo tra virgolette -
>
> - Mostra testo tra virgolette -

Yeah, I forgot. :\


--- Giampaolo
http://code.google.com/p/pyftpdlib



More information about the Python-list mailing list