Python os.walk用于未安装驱动器号的未安装驱动器

问题描述 投票:1回答:1

好,所以我编写了一个简单的Python代码,该代码比较2个文件夹中的所有文件,并从其中一个文件夹中删除重复的文件。我已经使用了几个星期,并且在所有硬盘上都可以正常使用。但是当我连接手机时,os.walk似乎根本找不到该地址

电话:Blackberry Key2(android)平台:Jupyter笔记本问题:从USB连接时,手机似乎缺少驱动器号(请参见屏幕截图)。我不知道那是什么意思。This PC screenshot我正在输入os.walk命令在计算机中显示的路径,但不会读取它。

path2 = r“ RG0005 \ BlackBerryBBF1006 \ Internal shared storage \ Pictures”

我尝试搜索论坛,但我想我不知道没有驱动器号的驱动器是什么,找不到任何相关的]

任何帮助表示感谢!!谢谢!

Python笔记本代码:

import os
import pandas as pd
import csv
from datetime import datetime

pd.set_option('display.max_colwidth', 700)

#COMPARE THIS
path1 = r"F:\1_BBK1_20190623_Img_Bckup\1_Pictures"

#DELETE FROM PATH
path2 = r"RG0005\BlackBerryBBF1006\Internal shared storage\Pictures"

f1 = [] #path
f2 = [] #path
a1 = [] #filename
a2 = [] #filename

for root, dirs, files in os.walk(path1):
    for file in files:
        if (file.endswith(".jpg") 
            or file.endswith(".png") 
            or file.endswith(".jpeg") 
            or file.endswith(".mov")  
            or file.endswith(".mp4") 
            or file.endswith(".pdf") 
            or file.endswith(".xlsx") 
            or file.endswith(".txt")):
            f1.append(os.path.join(root))
            a1.append(os.path.join(file))
ds1 = {"Path":f1,"filename":a1}
df1 = pd.DataFrame(ds1)

for root, dirs, files in os.walk(path2):
    for file in files:
        if (file.endswith(".jpg") 
            or file.endswith(".png") 
            or file.endswith(".jpeg") 
            or file.endswith(".mov")  
            or file.endswith(".mp4") 
            or file.endswith(".pdf") 
            or file.endswith(".xlsx") 
            or file.endswith(".txt")):
            f2.append(os.path.join(root))
            a2.append(os.path.join(file))
ds2 = {"Path":f2,"filename":a2}
df2 = pd.DataFrame(ds2)
# df2.head()
python directory path filenames os.walk
1个回答
0
投票

这样的MTP设备不是普通驱动器,您不能通过路径名访问它。

您唯一的解决方案是使用MTP库连接到设备(或在手机上安装另一个文件服务器,例如WebDav,FTP或SFTP服务器并连接到该设备),或使用COM组件通过以下方式完成此操作Windows(但不是常规路径。这很难)。

© www.soinside.com 2019 - 2024. All rights reserved.