无法在python程序中打开下载目录

时间:2019-06-11 15:12:55

标签: python

我正在编写一个python程序,告诉我没有。我根据文件类型下载的文件,例如4个音频文件,3个视频文件等。但是我无法打开下载目录。是否有任何方法可以打开该目录,或者需要root / admin访问? >

这是代码

Scanner.py file:

import os
from core.GetPath import get_download_path

""" get downloads directory path (linux or windows) """
path = get_download_path()
path=path.replace('/','//')
path=path+"//"

audioFiles = []  
videoFiles = [] 
zipFiles = [] 
documentFiles = [] 
imageFiles = []  
otherFiles=[]    

print(path)

for file in os.listdir(path):
    try:
        if file.endswith(".mp3"):
            audioFiles.append(file)

        elif file.endswith(".docx"):
            documentFiles.append(file)

        elif file.endswith(".mp4"):
            videoFiles.append(file)

        elif file.endswith(".zip"):
            zipFiles.append(file)

        elif file.endswith(".jpge"):
            imageFiles.append(file)

        else:
            otherFiles.append(file)

    except Exception as e:
        raise e

get_download_path来自此处: https://stackoverflow.com/a/48706260/11594438

输出:

//home//nandan//downloads//
Traceback (most recent call last):
  File "/media/nandan/G/Study/Learning/filedivider/Scanner.py", line 17, in <module>
    for file in os.listdir(path):
FileNotFoundError: [Errno 2] No such file or directory: '//home//nandan//downloads//'

Process finished with exit code 1

0 个答案:

没有答案