亚洲激情专区-91九色丨porny丨老师-久久久久久久女国产乱让韩-国产精品午夜小视频观看

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

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

發布時間:2020-09-20 06:20:22 來源:腳本之家 閱讀:153 作者:正經男大學生BRLF 欄目:開發技術

如下所示:

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個文件夾,
圖片存儲在path處
給每個文件夾分配150張圖片(將9000張圖片平均分配到60個文件夾)

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)

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

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

额济纳旗| 延寿县| 玉树县| 泰州市| 什邡市| 广平县| 乌海市| 克什克腾旗| 阿坝| 阿城市| 思南县| 横峰县| 博野县| 兴国县| 将乐县| 新源县| 定州市| 中卫市| 西吉县| 民县| 宾川县| 肥乡县| 类乌齐县| 柯坪县| 梁河县| 滨州市| 仪征市| 巩义市| 饶平县| 沿河| 皋兰县| 噶尔县| 井冈山市| 崇阳县| 宜丰县| 依兰县| 天津市| 邹城市| 南皮县| 凯里市| 融水|