如何检查索引文件中是否存在文件?

2024-04-26 21:56:39 发布

您现在位置:Python中文网/ 问答频道 /正文

如何检查物理文件是否位于索引文件中?你知道吗

例如:

假设在C:\Users文件夹中有5个文件。你知道吗

我有一个文件链接到这个位置

C:\Users\1.txtC:\Users\2.txtC:\Users\3.txtC:\Users\4.txt

我们可以看到索引文件中的C:\Users缺少一个文件?你知道吗

我该怎么做?如果你能给我点办法,那就太好了。有可能做这种事吗?你知道吗


Tags: 文件txt文件夹链接物理users办法
1条回答
网友
1楼 · 发布于 2024-04-26 21:56:39
path = "C:\Users"
for file_item in os.listdirs(path):
    file_item_full = path + "/" + file_item
    #check if the file_item_full name exists in the index file

我想这样做,你可以先读取文件,并添加一个列表中的所有行,这样你就不会一直读取索引文件。你知道吗

相关问题 更多 >