[問題] 中文檔名問題
Console default big5
Python Shell(GUI) Unicode
Windows XP SP3 BIG5, Python 2.7.1
--------------------------------------------------
#coding=utf-8
import os
import sys
#reload(sys)
#sys.setdefaultencoding('utf-8')
fileList = []
rootdir = unicode(sys.argv[1])
#rootdir = u'c:\'
for root, subFolders, files in os.walk(rootdir):
for file in files:
v = os.path.join(root,file)
print v
#f=open(v.encode(sys.getfilesystemencoding()), "r")
f=open(v, "r")
f.close()
fileList.append(os.path.join(root,file))
print len(fileList)
---------------------------------------------------
c:\test\SYMANTEC防火墙.wps
上面的程式在 Console 跑時
程式最前面加了 #coding=utf-8 在繁体中文的檔名中都沒什麼問題,
但遇到了簡体中文, 就會出錯了 .
上面程式在 Python Shell(GUI) 跑時
在這個環境下跑都沒什麼問題(簡体中文 OK), 但 GUI 很吃資源, print 太多東西很快就掉了(很慢)
請問要怎麼讓 Console 下可以處理簡体中文檔名?
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 220.135.121.210
※ 編輯: zha0 來自: 220.135.121.210 (07/03 19:07)
→
07/03 22:17, , 1F
07/03 22:17, 1F
→
07/03 22:18, , 2F
07/03 22:18, 2F
→
07/04 11:08, , 3F
07/04 11:08, 3F
→
07/04 11:22, , 4F
07/04 11:22, 4F
→
07/04 11:23, , 5F
07/04 11:23, 5F
→
07/04 11:24, , 6F
07/04 11:24, 6F
→
07/04 11:26, , 7F
07/04 11:26, 7F
→
07/04 11:28, , 8F
07/04 11:28, 8F
→
07/04 11:30, , 9F
07/04 11:30, 9F
→
07/04 11:30, , 10F
07/04 11:30, 10F
※ 編輯: zha0 (1.160.12.39), 07/19/2014 21:47:48