# -*- coding:utf-8 -*-import os
# os.system('net use z: \\10.147.142.173\ipc$ "admin`12" /user:"F7689344"')classCopyFile(object):defcopyFileDir(self, srcFilename, desFilename):
status =True
res_list =[]try:
fileList = os.listdir(srcFilename)
fileList =[img_path for img_path in fileList if
img_path.endswith(".jpeg")andnot img_path.startswith(".")]#文件格式筛选,此处可针对文件进行修改for eachFile in fileList:
sourceF = os.path.join(srcFilename, eachFile)
targetF = os.path.join(desFilename, eachFile)if os.path.isdir(sourceF):ifnot os.path.exists(targetF):
os.makedirs(targetF)
stat = self.copyFileDir(sourceF, targetF)
res_list.append(stat)else:
stat = self.copyFile(sourceF, targetF)
res_list.append(stat)iflen(set(res_list))>1:
status =Falseexcept Exception as e:
status =Falsereturn status
defcopyFile(self, srcFilename, desFilename):
copyCommand ='copy'+' "'+ srcFilename +'" '+'"'+ desFilename +'"'try:
stat = os.system(copyCommand)
status =Trueif stat ==0elseFalseexcept Exception as e:
status =Falsereturn status
if __name__ =='__main__':
local_dir ="e:/ng"#本地文件夹路径
imgDirPath ="\\\\10.147.142.164\\c_it_2\\C_series"#共享文件夹路径
cf = CopyFile()ifnot os.path.exists(local_dir):
os.makedirs(local_dir)
status = cf.copyFileDir(imgDirPath, local_dir)