如下所示:
在云溪等地區(qū),都構(gòu)建了全面的區(qū)域性戰(zhàn)略布局,加強(qiáng)發(fā)展的系統(tǒng)性、市場(chǎng)前瞻性、產(chǎn)品創(chuàng)新能力,以專注、極致的服務(wù)理念,為客戶提供成都做網(wǎng)站、成都網(wǎng)站制作 網(wǎng)站設(shè)計(jì)制作按需網(wǎng)站設(shè)計(jì),公司網(wǎng)站建設(shè),企業(yè)網(wǎng)站建設(shè),成都品牌網(wǎng)站建設(shè),網(wǎng)絡(luò)營銷推廣,外貿(mào)營銷網(wǎng)站建設(shè),云溪網(wǎng)站建設(shè)費(fèi)用合理。import os import shutil #path of imgr path = 'D:\\BaiduNetdiskDownload\\newim\\' #path of folder folderPath = 'D:\\BaiduNetdiskDownload\\folderSort\\' peopleNumber = 61 #new 61 folder numbers as sort_folder_number[61] sort_folder_number = [x for x in range(0,peopleNumber)] # makedir 61 folders ''' demo功能說明: 在folderPath處新建60個(gè)文件夾, 圖片存儲(chǔ)在path處 給每個(gè)文件夾分配150張圖片(將9000張圖片平均分配到60個(gè)文件夾) Tips: 1: os.path.join(path2,path3...) this function is used to combine the path,it returns a path which is 'path2/path3...' 2: os.makedirs(path) this function is used to make a directory(new folder) in the path param 3: shutil.move(oldPath,newPath) this function is used to move file from param1 to param 2 4: os.path.exists(path) this function is used to check the filePath(param1) whether exists ''' for number in sort_folder_number: new_folder_path = os.path.join(folderPath,'%s'%number)#new_folder_path is ‘folderPath\number' if not os.path.exists(new_folder_path): os.makedirs(new_folder_path) print("new a floder named "+str(number)+'at the path of '+ new_folder_path) #give the img list file_list = os.listdir(path) '''define the first foloderNumber''' folderNumber = 1 print('there are '+str(len(file_list))+' files at the path of '+path) for i in range(0,len(file_list)): old_file_path = os.path.join(path,str(i)+'.jpg') if os.path.isdir(old_file_path): '''if the path is a folder,program will pass it''' print('img does not exist ,path=' + old_file_path+' it is a dir' ) pass elif not os.path.exists(old_file_path): '''if the path does not exist,program will pass it''' print('img does not exist ,path='+old_file_path) pass else: '''define the number,it decides how many imgs each people process''' number = 150 #int(len(file_list)/peopleNumber) if(i%number ==0): folderNumber +=1 new_file_path = os.path.join(folderPath,'%s'%(folderNumber)) if not os.path.exists(new_file_path): print('not exist path:'+new_file_path) break shutil.move(old_file_path,new_file_path) print('success move file from '+ old_file_path +' to '+new_file_path)