21 lines
663 B
Python
21 lines
663 B
Python
|
import pefile
|
||
|
import os
|
||
|
from tqdm import tqdm
|
||
|
def is_pe(file_path):
|
||
|
try:
|
||
|
pe = pefile.PE(file_path)
|
||
|
return True
|
||
|
except pefile.PEFormatError:
|
||
|
return False
|
||
|
|
||
|
def delete_non_pe_files(folder_path):
|
||
|
for file_name in tqdm(os.listdir(folder_path)):
|
||
|
file_path = os.path.join(folder_path, file_name)
|
||
|
if os.path.isfile(file_path):
|
||
|
if not is_pe(file_path):
|
||
|
print(f"Deleting non-PE file: {file_path}")
|
||
|
os.remove(file_path)
|
||
|
else:
|
||
|
print(f"Skipping non-file item: {file_path}")
|
||
|
if __name__ == '__main__':
|
||
|
delete_non_pe_files(r"D:\detect_exp_d\data\benign_pre")
|