[Python-bugs-list] [ python-Bugs-773286 ] nconsistant results for os.listdir,os.path.isdir on W2k

SourceForge.net noreply@sourceforge.net
Wed, 23 Jul 2003 16:36:03 -0700


Bugs item #773286, was opened at 2003-07-17 14:36
Message generated for change (Comment added) made by remerson
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=773286&group_id=5470

Category: Python Library
Group: Python 2.2.3
Status: Open
Resolution: None
Priority: 5
Submitted By: Richard F. Emerson (remerson)
Assigned to: Nobody/Anonymous (nobody)
Summary: nconsistant results for os.listdir,os.path.isdir on W2k 

Initial Comment:
Inconsistant results when using
os.listdir,os.path.isdir and os.path.isfile on the
win200 platform.  Run the following script and compare
with a directroy view.  They do not match for the
second directory of the two.

""" to separate the sub directories from the files in a
directory"""
import os
p1=os.getcwd()
x=os.listdir(p1)
p2= os.path.join("c:\","python~1","Tools")
y=os.listdir(p2)
#cwd = os.path.join("c:\")
#cwd=cwd+"\doc\"
#cwd="c:\python~1\Doc"
#cwd=cwd+"\Qualcomm"+"\Eduora"
#print x,y
print "path",p1,"\n"
print "directories","\n"
for item in x:
    #print item
    if os.path.isdir(item): print "   ",item
print "\n","files","\n"
for item in os.listdir(cwd):
    if os.path.isfile(item): print "   ",item
print "path",p2,"\n"
print "directories","\n"
for item in y:
    #print item
    if os.path.isdir(item): print "   ",item
print "\n","files","\n"
for item in os.listdir(cwd):
    if os.path.isfile(item): print "   ",item

the lists x and y do contain all the file and directory
names and one would expect the same sorting of both
lists into directories only and files only.  Not so on
my machine.

Results

path C:\PYTHON~1 

directories 

    DLLs
    Doc
    include
    Lib
    libs
    Qualcomm
    tcl
    Tools

files 

    Circle.py
    Circle.pyc
    INSTALL.LOG
    LICENSE.txt
    log.bak
    Log.py
    Log.pyc
    mailspin.py
    mailspin.pyc
    mailspin1.py
    NEWS.txt
    py.ico
    pyc.ico
    pycon.ico
    python.exe
    pythonw.exe
    README.txt
    Requirements for the Message Separator.doc
    session.txt
    test dirs.py
    test dirs1.py
    test file.txt
    w9xpopen.exe
path c:\python~1\Tools 

directories 


files 

    Circle.py
    Circle.pyc
    INSTALL.LOG
    LICENSE.txt
    log.bak
    Log.py
    Log.pyc
    mailspin.py
    mailspin.pyc
    mailspin1.py
    NEWS.txt
    py.ico
    pyc.ico
    pycon.ico
    python.exe
    pythonw.exe
    README.txt
    Requirements for the Message Separator.doc
    session.txt
    test dirs.py
    test dirs1.py
    test file.txt
    w9xpopen.exe


The tools sub directory is as delivered with the
distribution.  The Python~1 directory has had a few
files added.

Though I am new to Python, I tried locating the
functions or classes that implemented the dirlist,
isdir and isfile with only limited success.  I looked
in os, os.path and ntpath.

I can be reached by phone at 818.354.3848 if more
immediate communications is required to understand the
problem (mine or the library's ) and resolve it.

Regards

Dick

----------------------------------------------------------------------

>Comment By: Richard F. Emerson (remerson)
Date: 2003-07-23 16:36

Message:
Logged In: YES 
user_id=824995

Recommend closing this bug as the vagueness lies in the
documentation.  Alternatively, return an error if the path
provided is not an abspath.  Either way the documentation
should be updated.

The library routines os.path.isdir() and os.path.isfile()
require that the path argument be an abspath.  In the
absence of an abspath they use the cwd as the pbase path and
prepend it to the data found with the os.listdir() request.
 Hence it works for the first case I tried bu not the
second, yet it doesnt complain.

Thanks for your rapid response.  Checking into the questions
asked led to the solution.

Regards

Dick

----------------------------------------------------------------------

Comment By: Raymond Hettinger (rhettinger)
Date: 2003-07-17 19:11

Message:
Logged In: YES 
user_id=80475

What is the issue?

* Is it a matter of os.listdir() having a sort order different 
from that shown by another windows tool? If so, then that is 
not a bug (the sort order is not guaranteed by the underlying 
o.s.).

* Is there another tool that makes different idenfications of 
what is a directory vs what is a file?  If so, please include a 
DOS listing of the file attributes ("attrib *.*") and a similar 
list from Python:
  for filename is os.listdir(p):
     print filename, os.isdir(filename), os.isfile(filename)

* Is there any internal inconsistency within Python.  If so, 
please show the comparative result.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=773286&group_id=5470