搜索计算机上的所有目录

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

我对OS模块还很陌生,我正在尝试制作一个循环遍历计算机上所有目录以查找文件的函数。到目前为止,我能够找到有关如何遍历给定路径的目录的解决方案,但不能针对计算机上的每个目录。

任何帮助将不胜感激。

提前谢谢您

search directory operating-system
1个回答
0
投票
import os
import re

drives = [ chr(x) + ":" for x in range(65,90) if os.path.exists(chr(x) + ":") ] #find 
all of the drives on the computer


for drive in drives: #loop through all of the drives
   path = drive + '\\'
     for r, d, f in os.walk(path):
        for file in f:
           ....

我想知道如何在Linux上更新它,因为在Linus中没有驱动器号。

先谢谢您。

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