python對資料夾中的檔案分類處理
阿新 • • 發佈:2018-12-20
把演算法檢測出來目標進行分類,車輛行人非機動車自然物體,python真好用,不用學蒙都能寫對
import os import shutil def GetPathNameExt(filename): (filepath,tempfilename) = os.path.split(filename) (shotname,extension) = os.path.splitext(tempfilename) return filepath,shotname,extension def GetFileSize(filepath): fsize = os.path.getsize(filepath) #fsize = fsize/float(1024*1024) #print(fsize) return round(fsize, 2) def main(): print("hello dir %d" % 10) os.chdir("F:\\wserver\\info\\2_1851\\0") lis = os.listdir() for ls in lis: print("file:%s, size:%d" %(ls, GetFileSize(ls))) if 500 < GetFileSize(ls) < 5000: path, name, ext = GetPathNameExt(ls) print("path:%s, name:%s, ext:%s" %(path, name, ext)) shutil.copy(ls, "people/%s" % ls) strname = name strname += ".jpg" if os.path.exists(strname): shutil.copy(strname, "people/%s" % strname) strname = name strname += "_l.jpg" if os.path.exists(strname): print("file is exists:%s"%strname) shutil.copy(strname, "people/%s" % strname) if __name__ == '__main__': main()