复制某文件夹下指定拓展名的文件,指定拓展,将给定的文件夹下,递归查


将给定的文件夹下,递归查找某拓展名的文件,并复制到指定的位置

winXP

#-*- coding:utf-8-*-import osimport shutildef filter_ext(args,dirn,fln):    for fls in fln:        if fls.lower().endswith(args[1].lower()):            args[0].append(os.path.join(dirn,fls))def cp_ext(ext,src=".",dest="."):    if not os.path.exists(dest):        v=raw_input("The target path doesn't exist,want going?[y]")        if v in ['y','Y']:            os.mkdir(dest)        else:            return False    assert os.path.isdir(src) or os.path.isdir(dest),TypeError("ALL path must be Dir")    assert os.path.exists(src),ValueError("Source Path Must exists!")    ll=[]    os.path.walk(src,filter_ext,(ll,ext))    for l in ll:        print("Copying File:"+l)        shutil.copy(l,dest)#该片段来自于http://byrx.net

评论关闭