如何从Python中读取USB连接的电话的文件



我制作了一个python程序,该程序在输入路径的目录中读取所有文件,然后对它们做一些事情,然后将某些内容输出到.txt文件中。

我使用OS.Walk读取目录中的文件

def dir_read(pathName = str(), fileList=[]):  #fileList is output
    cur_dir = [i[2] for i in os.walk(pathName)] #current directory
    for i in cur_dir:
        for j in i:
            fileList.append(j)

,然后检查正确输入的路径

fileList=[]
while True:
    dir_read(pathName, fileList) #FUNCTION CALL
    if not fileList:  #if it is empty
      print("The path is written incorrectly, is empty or does not exist. Please re-enter now or "
              "close the program and enter it inside PATH.txt:")
      pathName = str(input())
    else:
        break    #if the list is not empty (the path is entered correctly) the while loop breaks

但是,如果我输入诸如This PCNokia 6.1Card SD之类的内容,它会一直给我错误消息。我还注意到桌面或文档之类的事情也会发生同样的事情。但是,如果我输入诸如C:Program Files (x86)Notepad++之类的东西,它可以很好地工作。

我也尝试用替换/,但它不起作用。

我的手机没有像F:您可以在此处看到的特定驱动器:https://i.stack.imgur.com/AY53B.JPG

我正在使用Windows10。

我该如何修复?

我相信您的目录应该是这样的:

在Linux上:

media/This PC/Nokia 6.1/Card SD

在Windows上:您需要知道可以运行此命令的驱动器字母:

C:>wmic logicaldisk where drivetype=2 get deviceid, volumename, description

假设它返回x:那么您的目录应该是这样的:

X:Nokia 6.1Card SD

我不确定您是否应该删除诺基亚6.1

尝试使用subst命令,如果您的名称上的空格放在引号上前任: subst E: "The Name Goes Here"

最新更新