#拷貝當前目錄下的文件夾所有內容
#1、lexists和exists的區別還需要繼續學習
#2、Readline後面會帶着換行符,直接賦值給exist()函數總會返回false,需要strip掉'\n'換行符
import os.path
from shutil import copytree,ignore_patterns
'''
功能:通過task.txt文檔中的文件夾名字,拷貝對應目錄文件--》指定盤符下面
1、copyTree
2、os.path.exist()
3、strip去掉readlines的換行符
'''
winDriver = "E:"
newDictory = "西瓜視頻"
try:
#print(os.environ)
currentDir = os.path.abspath(os.curdir)
count = 0
with open(file = "task.txt",mode = 'r',encoding = "utf-8") as fp:
ls = fp.readlines()
for item in ls:
count+=1
fsrc = os.path.join(currentDir,item.strip('\n'))
fdst = os.path.join(winDriver,os.sep,newDictory,item.strip('\n'))
print(count,end = '')
#print(fsrc)
#print(os.path.lexists(fsrc))
if os.path.lexists(fsrc):
if not os.path.lexists(fdst):
copytree(fsrc ,fdst,ignore=ignore_patterns('*.wav', '*.jpg'))
print("拷貝完成",fdst)
else:
print("已存在",fdst)
else:
print("不存在",fsrc)
fsrc = ""
fdst = ""
except IOError as e:
pass
finally:
pass