#coding=utf-8
import os
import shutil
folder_capacity = 10000
def copy_files(src_dir, dest_dir):
if not os.path.exists(dest_dir):
os.mkdir(dest_dir)
count = 0
for item in os.listdir(src_dir):
abs_item = os.path.join(src_dir, item)
dst_name = os.path.join(dest_dir, item)
if os.path.exists(abs_item):
count +=1
shutil.copy(abs_item,dst_name)
if count >= 20000:
break
print("done")
return 0
def move_file(src_dir,target_dir):
if not os.path.exists(target_dir):
os.mkdir(target_dir
count = 0
for item in os.listdir(src_dir):
src_name = os.path.join(src_dir,item)
target_name = os.path.join(target_dir,item)
count +=1
shutil.move(src_name,target_name)
if count>=20000:
break
if __name__ =='__main__':
move_file('./alexnet/data_light/lighter','./alexnet/data_light/light')
#!/usr/bin/python
import os
for root , dirs, files in os.walk('.\hei'):
#file =os.path.splitext(files)
nums= 0
for name in files:
if name.endswith(".jpg"):
#if name[:-4].endswith("idcardimage"):
nums +=1
print("start")
os.remove(os.path.join(root, name))
print ("Delete File: " + os.path.join(root, name))
if nums >1:
break
print("the sum of remove items is:\n%d" %(nums))
print ("over!")
#后面if语句是删除文件名指定字符后缀,这里指定字符是"idcardimage",之后的if语句是用来设置删除文件的个数的,最后输出删除文件数量。