1 import os 2 import re 3 import shutil 4 pathJiaoBen = r'C:UsersjjwDesktop601_英语沪教版九年级下册' #脚本 5 pathRtf = r'D:XiZhiContentSourceSVN课文初三年级下册英语601_英语沪教版九年级下册' #课文rtf 6 #C:UsersjjwDesktop601_英语沪教版九年级下册1_Unit1 Great exploration1_class_11_预习3_课文朗读 7 8 #for root1, dirs1, files1 in os.walk(path1): #三个参数:分别返回1.父目录 2.所有文件夹名字(不含路径) 3.所有文件名字 9 for rootRtf, dirRtf, filesRtf in os.walk(pathRtf): 10 for fileRtf in filesRtf: 11 numUnit,numClass,other = fileRtf.split('-',2) 12 rtf = os.path.join(rootRtf,fileRtf) 13 #print (rtf) 14 #print(numUnit+'..'+numClass) 15 pathLangDu = r'\.*年级.*\'+numUnit +r'_.*\'+numClass+r'.*d\1_预习\3_课文朗读$' 16 #print(pathLangDu) 17 for rootJiaoBen, dirJiaoBen, filesJiaoBen in os.walk(pathJiaoBen): 18 19 if re.findall(pathLangDu,rootJiaoBen): 20 #print(rootJiaoBen) 21 shutil.copy(rtf,rootJiaoBen+'\' + '课文.rtf') 22 '''else: 23 print("未找到")''' 24
r''要用单引号,r=regular,使引号里的不用转意。