国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

python實現將多個文件分配到多個文件夾的方法

2020-02-16 00:30:13
字體:
來源:轉載
供稿:網友

如下所示:

import osimport shutil#path of imgrpath = 'D://BaiduNetdiskDownload//newim//'#path of folderfolderPath = '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個文件夾,圖片存儲在path處給每個文件夾分配150張圖片(將9000張圖片平均分配到60個文件夾)Tips:1: os.path.join(path1,path2...)this function is used to combine the path,it returns a path which is 'path1/path2...'2: os.makedirs(path)this function is used to make a directory(new folder) in the path param3: shutil.move(oldPath,newPath)this function is used to move file from param1 to param 24: 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 listfile_list = os.listdir(path)'''define the first foloderNumber'''folderNumber = 1print('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)

以上這篇python實現將多個文件分配到多個文件夾的方法就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持武林站長站。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 烟台市| 克山县| 格尔木市| 肥西县| 虞城县| 桐乡市| 武山县| 定边县| 扶沟县| 牡丹江市| 伊通| 罗城| 尉犁县| 杂多县| 托里县| 堆龙德庆县| 凌源市| 建阳市| 化州市| 定结县| 肥东县| 新竹市| 依兰县| 云浮市| 临沂市| 黑山县| 郓城县| 余庆县| 吴忠市| 年辖:市辖区| 金门县| 宜兴市| 泽州县| 新平| 和政县| 遵义市| 双桥区| 呼伦贝尔市| 宣威市| 错那县| 绵竹市|