[Tutor] listdir, ispath and unicode (followup question)

Sean 'Shaleh' Perry shalehperry@attbi.com
Wed, 31 Jul 2002 13:38:32 -0700 (PDT)


On 31-Jul-2002 Poor Yorick wrote:
> Thank you for your previous responses.  I am still having this difficulty:
> 
>  >>> filename = os.path.join(os.getcwd(), os.listdir(os.getcwd())[0])
>  >>> filename
> 'd:\\tmp2\\???????'
>  >>> os.path.isfile(filename)
> 0
> 
> 
> The file, 'd:\\tmp2\\???????', is a text file which I created for 
> testing this problem.  Any ideas why os.path.isfile function does not 
> recognize this file?
> 

os.path is a wrapper for various operating systems.  The isfile() function is
itself a wrapper around os.stat()

    try:
        st = os.stat(path)
    except os.error:
        return 0
    return stat.S_ISREG(st[stat.ST_MODE])

so, does os.stat() raise os.error? or is the stat info returned incorrect.  If
os.error is raised there should be more information available as well.  Try
doing the os.stat() call from the interactive interpreter.