【发布时间】:2020-06-13 22:22:28
【问题描述】:
好的,所以我编写了一个简单的 Python 代码,它比较了 2 个文件夹中的所有文件,并从其中一个文件夹中删除了重复项。我已经使用它几个星期了,它在我所有的硬盘上都运行良好。 但是当我连接手机时,os.walk 似乎根本找不到地址
电话:Blackberry Key2(安卓) 平台:Jupyter Notebook 问题:从 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