[Python-de] Anfängerfrage: Verzeichnisinhalt mit Variable vergleichen
Gerhard Häring
haering_python at gmx.de
Sun May 12 21:38:08 EDT 2002
* Marcus Klein <python at marcus1.de> [2002-05-11 16:54 +0200]:
> Hallo zusammen,
>
> habe folgendes Problem:
> Ich vergleich den Inhalt eines Verzeichnisses mit einer Variablen, um zu
> vermeiden, daß eine Datei, falls vorhanden überschrieben wird, leider
> klappt's noch nicht ganz so, wie ich es mir vorgestellt habe,
>
> Vielleicht kann mir jemand helfen ?
>
> --8<--
> for f in TOGET:
> print "getting remote file ", f
> fname = PATHTOFILE + f
Besser: os.path.join(PATHTOFILE, f)
> lfiles = os.listdir(PATHTOFILE)
> lfile = re.compile(f, re.M).search(lfiles, 1)
> if lfile:
> print "Warning: File exists locally"
> exit(5)
> -->8--
>
> führt zu:
>
> --8<--
> Traceback (most recent call last):
> File "py/getftp.py", line 33, in ?
> lfile = re.compile(f, re.M).match(lfiles, 1)
> TypeError: expected string or buffer
> -->8--
Tja, f ist wohl kein string und einen regulären Ausdruck muss man halt
als String angeben. Wahrscheinlich kommst du mit os.path.exists und
evtl. os.path.join/os.path.split auch einfacher zum Ziel.
Gerhard
--
This sig powered by Python!
Außentemperatur in München: 14.3 °C Wind: 1.1 m/s
More information about the Python-de
mailing list