[Tutor] listdir, ispath and unicode (followup question)
Poor Yorick
gp@pooryorick.com
Wed, 31 Jul 2002 15:16:56 -0600
I am running Windows 2000 English edition. The filename contains
cyrillic characters typed with a standard Windows 2000 IME when I
created the file. Here is the result of your suggestion:
filename = os.path.join(os.getcwd(), os.listdir(os.getcwd())[0])
>>> filename
'd:\\tmp2\\???????'
>>> os.stat(filename)
Traceback (most recent call last):
File "<pyshell#5>", line 1, in ?
os.stat(filename)
OSError: [Errno 2] No such file or directory: 'd:\\tmp2\\???????'
Sean 'Shaleh' Perry wrote:
>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.
>
>_______________________________________________
>Tutor maillist - Tutor@python.org
>http://mail.python.org/mailman/listinfo/tutor
>
>