#!/usr/bin/env python3
import os
files = []
for file in os.listdir():
if file == "vol.py" or file == "thekey.key": ## ignore in the encryption - ransomware and thekey files
continue
if os.path.isfile(file):
files.append(file)
print(files)发布于 2022-06-05 07:38:32
从标题中,我假设您正在查找C目录中的文件,但是您的python脚本位于其他地方,因此os.listdir()将返回该目录的文件。
您可以简单地在os.listdir()中传递目录的路径并获取C目录的目录。
path = 'C:\\'
os.listdir(path)https://stackoverflow.com/questions/72505500
复制相似问题