Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nconsistant results for os.listdir,os.path.isdir on W2k #38870

Closed
remerson mannequin opened this issue Jul 17, 2003 · 3 comments
Closed

nconsistant results for os.listdir,os.path.isdir on W2k #38870

remerson mannequin opened this issue Jul 17, 2003 · 3 comments
Labels
stdlib Python modules in the Lib dir

Comments

@remerson
Copy link
Mannequin

remerson mannequin commented Jul 17, 2003

BPO 773286
Nosy @rhettinger

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2003-07-23.23:36:03.000>
created_at = <Date 2003-07-17.21:36:56.000>
labels = ['invalid', 'library']
title = 'nconsistant results for os.listdir,os.path.isdir on W2k '
updated_at = <Date 2003-07-23.23:36:03.000>
user = 'https://bugs.python.org/remerson'

bugs.python.org fields:

activity = <Date 2003-07-23.23:36:03.000>
actor = 'remerson'
assignee = 'none'
closed = True
closed_date = None
closer = None
components = ['Library (Lib)']
creation = <Date 2003-07-17.21:36:56.000>
creator = 'remerson'
dependencies = []
files = []
hgrepos = []
issue_num = 773286
keywords = []
message_count = 3.0
messages = ['17099', '17100', '17101']
nosy_count = 2.0
nosy_names = ['rhettinger', 'remerson']
pr_nums = []
priority = 'normal'
resolution = 'not a bug'
stage = None
status = 'closed'
superseder = None
type = None
url = 'https://bugs.python.org/issue773286'
versions = ['Python 2.2']

@remerson
Copy link
Mannequin Author

remerson mannequin commented Jul 17, 2003

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

@remerson remerson mannequin closed this as completed Jul 17, 2003
@remerson remerson mannequin added invalid stdlib Python modules in the Lib dir labels Jul 17, 2003
@remerson remerson mannequin closed this as completed Jul 17, 2003
@remerson remerson mannequin added invalid stdlib Python modules in the Lib dir labels Jul 17, 2003
@rhettinger
Copy link
Contributor

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.

@remerson
Copy link
Mannequin Author

remerson mannequin commented Jul 23, 2003

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

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Python modules in the Lib dir
Projects
None yet
Development

No branches or pull requests

1 participant