Python脚本语言无法自动执行

时间:2020-07-07 04:07:18

标签: python

我按照互联网上的指示进行了脚本编写,以自动化计算机中的无聊内容。

我在执行时有一些错误,

谁能告诉我这是什么问题?并对此案提出建议。 代码:

# import python libraries

from os import listdir
from os.path import isfile, join
import os
import shutil


def file_organizer(mypath):
    '''
    A function to sort the files in a download folder
    into their respective categories
    '''
    files = [f for f in listdir(mypath) if isfile(join(mypath, f))]
    file_type_variation_list = []
    filetype_folder_dict = {}
    for file in files:
        filenamebrake = file.split('.')
        filetype = filenamebrake[len(filenamebrake) - 1]
        if filetype not in file_type_variation_list:
            file_type_variation_list.append(filetype)
            new_folder_name = mypath + '/' + filetype + '_folder'
            filetype_folder_dict[str(filetype)] = str(new_folder_name)
            if os.path.isdir(new_folder_name) == True:  # folder exists
                continue
            else:
                os.mkdir(new_folder_name)
    for file in files:
        src_path = mypath + '/' + file
        filenamebrake = file.split('.')
        filetype = filenamebrake[len(filenamebrake) - 1]
        if filetype in filetype_folder_dict.keys():
            dest_path = filetype_folder_dict[str(filetype)]
            shutil.move(src_path, dest_path)
    print("File Organization Completed " + str(mypath))
    mypath = 'C:/Users/snguyend/Downloads'


mypath = str(input("Enter Path "))
file_organizer(mypath)

执行cmd时出现错误消息

C:\Users\snguyend\Desktop\Python Anaconda>python organizebot.py
Enter Path
Traceback (most recent call last):
  File "organizebot.py", line 40, in <module>
    file_organizer(mypath)
  File "organizebot.py", line 14, in file_organizer
    files = [f for f in listdir(mypath) if isfile(join(mypath, f))]
FileNotFoundError: [WinError 3] The system cannot find the path specified: ''

C:\Users\snguyend\Desktop\Python Anaconda>

Link to code

0 个答案:

没有答案