ディレクトリを開き、正規表現を使用してパワーポイントの名前を取得し、ローカルでファイルを作成してその内容をコピーするプログラムを作成しようとしています。これを実行すると機能しているように見えますが、実際にファイルを開こうとすると、バージョンが間違っていると言われ続けます。
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()