深圳做網(wǎng)站建設(shè)的公司競價交易規(guī)則
測試1(直接把B文件夾移動到了A里,成為了A的子文件夾)
import os
import shutil# 移動文件夾,B文件夾在當(dāng)前目錄沒有了,跑到了A的子文件里
##
shutil.move('./example1/B/', './example1/A/')
測試2(B文件不動,將B文件里的所有的子文件夾移動到A內(nèi))
import os
import shutildef move_folder(source_folder, destination_folder,overlapp=False):# 創(chuàng)建目標(biāo)文件夾os.makedirs(destination_folder, exist_ok=True)destFileFolder = os.listdir(destination_folder)# 遍歷源文件夾中的所有文件和文件夾for subFileFolder in os.listdir(source_folder):print(subFileFolder)source_item = os.path.join(source_folder, subFileFolder)if(subFileFolder in destFileFolder):if(not overlapp):print("原始文件夾{}不移動!!!".format(source_item))else:# 把原始的文件給刪除,然后再移動print("未實(shí)現(xiàn),應(yīng)該首先把這個結(jié)果給刪除點(diǎn),然后復(fù)制過來。。。。")else:shutil.move(source_item, destination_folder)print("{}-->移動-->{}完成!!!".format(source_item,destination_folder))
# 示例用法# delete_list
file_path ='./example2/A/'
file_list = os.listdir(file_path)
# 從文件夾中刪掉
if(".DS_Store" in file_list):print("There is .DS_Store in filefolder, delete it!!!")file_list.remove(".DS_Store")os.remove(file_path+"/.DS_Store")
else:print("No .DS_Store in file folder")move_folder("./example2/B/","./example2/A/")
結(jié)果如下
移動子文件夾
import pickle
import os
import shutil
read_path="/Users/yxk/Desktop/核磁項目/527檢查修改mask/ThreeD_patient_list.pkl"
base_sample_path = "/Volumes/My Passport/yxk_move_sample/file/"
with open(read_path,"rb") as f: # Python 3: open(..., 'rb')ThreeD_patient_list=pickle.load(f)print(ThreeD_patient_list)for patient in ThreeD_patient_list:shutil.move(base_sample_path+patient,"/Volumes/My Passport/yxk_move_sample/ThreeDT1樣本/")