isdir, isfile broken under windows XP?

Martin v. Löwis martin at v.loewis.de
Thu May 22 02:57:04 EDT 2003


imcmeans at telus.net (Ian McMeans) writes:

> >>> os.listdir(r'f:\\')
> ['Apache2', 'console.log', 'Crimsonland', 'cygwin', 'movies',
> 'mozilla', 'mp3s', 'nerd stuff', 'new', 'pics', 'RECYCLER',
> 'soundforge', 'source', 'text', 'WINAMP']
> >>> filter(os.path.isfile, os.listdir(r'f:\\'))
> []
> >>> filter(os.path.isdir, os.listdir(r'f:\\'))
> ['RECYCLER']
> 
> Now, all of those enties of listdir's output are either files or
> directories, but they aren't being listed as such. This seems
> incorrect to me, and doesn't match the documentation.

If you really think about it, you will find that you are using it
incorrectly. You invoke calls like

os.path.isdir("console.log")
os.path.isdir("RECYCLER")

Now, these are all relative paths. What *parent directory* should
Python assume? You are assuming r'f:\\', but how could Python possibly
know about this assumption?

Regards,
Martin





More information about the Python-list mailing list