Handling Links: https://www.jianshu.com/p/c8be54282e77
1 "" " 2 specify suffix path may traverse the input file, mainly used to screen picture, the picture is divided into three horizontal screen, vertical screen were stored in the two folders . 4 " "" . 5 from the PIL Import Image . 6 Import OS . 7 Import the os.path . 8 from tqdm Import tqdm . 9 Import the shutil 10 # function to find all files in the path specified in the path 11 # function to find all files in the path specified in the path 12 is DEF get_file (path): 13 is List1 = [] # All files used to store the searched recursively passed to function 14 the fileList the os.listdir = (path) #Get all the files under the directory path 15 for filename in the fileList: 16 pathTmp the os.path.join = (path, filename) # Get the path after path and filename compositions . 17 IF os.path.isdir (pathTmp): # If a directory 18 get_file = a (pathTmp) # the recursive lookups (note must be accepted variables, or on the wrong) 19 for i in a: 20 list1.append (i) 21 the else : 22 list1.append (pathTmp) 23 return List1 24- 25 path = iNPUT ( ' Please input path:' ) .Strip () # .strip () to remove leading and trailing spaces 26 27 file_path_list = get_file (path) 28 29 # screening suffix function, passing a list of all suffixes, and the suffix to be screened (default filter txt file) 30 DEF shai_xuan_hou_zhui (file_path_list, hou_zhui = ' .txt ' ): 31 is 32 List2 = [] # for screening good path to the file storage 33 is for filepath in file_path_list: 34 is # os.path.splitext (): file name separated extension 35 IF os.path.splitext (filepath) [. 1] == hou_zhui: 36 list2.append (filepath) 37 [ # Print (filepath + '\ n-') 38 is 39 return List2 40 41 is # hou_zhui = '. JPG' 42 is # py_list = shai_xuan_hou_zhui (file_path_list, '. Py') # py file filter 43 is pig_list = shai_xuan_hou_zhui (file_path_list, ' .jpg ' ) # screening jpg format file 44 is # Print (txt_list) 45 Folder1 = # stored in the horizontal screen image address 46 is folder2 = # storing portrait image address 47 48 for I in tqdm (Range (len (pig_list))): 49 = Lujing pig_list [I] 50 picture=Image.open(lujing) 51 width=picture.width 52 height=picture.height 53 picture.close() 54 if width > height: 55 shutil.move(lujing,folder1) 56 else: 57 shutil.move(lujing,folder2)