我正在尝试制作一个程序,它可以打开一个目录,然后使用正则表达式获取PowerPoint的名称,并在本地创建文件并复制它们的内容。当我运行它时,它似乎工作正常,但实际上当我尝试打开这些文件时,它们一直显示版本不正确。
from urllib.request import urlopen
import re
urlpath = urlopen('http://www.divms.uiowa.edu/~jni/courses/ProgrammignInCobol/presentation/')
string = urlpath.read().decode('utf-8')
pattern = re.compile('ch[0-9]*.ppt') #the pattern actually creates duplicates in the list
filelist = pattern.findall(string)
print(filelist)
for filename in filelist:
remotefile = urlopen('http://www.divms.uiowa.edu/~jni/courses/ProgrammignInCobol/presentation/' + filename)
localfile = open(filename,'wb')
localfile.write(remotefile.read())
localfile.close()
remotefile.close()