question about os.path.isdir

P Brian paul at
Tue Mar 18 00:03:50 CET 2003

Have you tried joining the base + filename using os.path.join

I can sometimes find strnge things happening with \ when I try straight
string joins. -

> for filename in basefilelist:
           filePath = os.path.join(base, filename)
>         if (os.path.isdir(filePath)):

An non existent path will fail as well as a valid path that is not a file...


"BearFx" <bearfx at> wrote in message
news:de1ef65d.0303171303.7d6d3ee3 at
> I am new to python, and am working on a small script to manipulate
> some files.  My files are stored on a network directory, mapped as u:
> .  This is a netware server, with a unc(for example) of
> \\nw-server\data\sec\users\user1
> I used os.listdir("u:\\:) to get a list of files, then iteratered
> through them as below.  The problem is os.path.isfile(base + fn) fails
> every time.  .isdir works OK.  I have tried using both the mapped
> drive, and the unc path.
> import os
> base = "u:\\"
> basefilelist = os.listdir(base)
> for filename in basefilelist:
>         if (os.path.isdir(base + filename)):
>               print "Dir " + filename      #this works
>         elif (os.path.isfile(base + filename)):
>               print "File " + filename     #no matter the file i never
> get here
>         else:
>               print "Unknown " + filename     #all files print here
> With a little more testing, I foung that every test fails for the
> file, even os.path.exists .  However, if I set base to a local
> directory, it works normally.
> Any assistance with this problem would be appreciated.  I am running
> Windows XP sp 1 with Novell Netware Client 4.83 and Python 2.2

More information about the Python-list mailing list