Issue773286
This issue tracker has been migrated to GitHub,
and is currently read-only.
For more information,
see the GitHub FAQs in the Python's Developer Guide.
Created on 2003-07-17 21:36 by remerson, last changed 2022-04-10 16:10 by admin. This issue is now closed.
Messages (3) | |||
---|---|---|---|
msg17099 - (view) | Author: Richard F. Emerson (remerson) | Date: 2003-07-17 21:36 | |
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 |
|||
msg17100 - (view) | Author: Raymond Hettinger (rhettinger) * | Date: 2003-07-18 02:11 | |
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. |
|||
msg17101 - (view) | Author: Richard F. Emerson (remerson) | Date: 2003-07-23 23:36 | |
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 |
History | |||
---|---|---|---|
Date | User | Action | Args |
2022-04-10 16:10:01 | admin | set | github: 38870 |
2003-07-17 21:36:56 | remerson | create |