一个错误可能是因为shutil

时间:2018-01-16 06:11:14

标签: python-3.x shutil

**行有什么问题? "打印"以上工作正常。

import os
import time
import shutil


def trace_pdf_ppt(directory):
    try:
        flag = False
        assert os.path.isdir(directory)
        target = os.path.join('/Users/yanlu/Desktop/',               "pptPdf"+time.strftime('%Y%m%W'))
        print("target", target)
        if not os.path.exists(target):
            os.mkdir(target)
        for root, dirs, files in os.walk(directory, topdown=True):
            for fl in files:
                print(fl)
                if fl.split('.')[-1] == "pdf" or fl.split('.')[-1] ==    'ppt' or fl.split('.')[-1] == 'pptx':
                    print("copy successfully")
                    **shutil.copy(fl, target)**

                    flag = True
        if not flag:
            print("No ppt or pdf.")
        return target

    except:
        print("Trace Error")
        return ''

0 个答案:

没有答案