- 论坛徽章:
- 0
|
代码如下,
1.为何这个获取文件crc32值的脚本遇到中文命名或中文路径就会打开文件失败呢?
2. 为何将_path=('c:\\windows\\新建文本文档.txt') 修改成 _path=('%windir%\\新建文本文档.txt')
后,%windir% 不会被转译成c:\windows 呢?
请大家指点下
# _*_ coding: utf-8 _*_
from ctypes import *
import zlib
import os
_path=('c:\\windows\\新建文本文档.txt')
def getFileCRC(_path):
try:
blocksize = 1024 * 64
f = open(_path,"rb")
str = f.read(blocksize)
crc = 0
while(len(str) != 0):
crc = zlib.crc32(str, crc)
str = f.read(blocksize)
f.close()
except:
print "error:get file crc error!"
return 0
return c_uint(crc).value
print getFileCRC(_path)
print _path |
|
|