Building a malware classifier for a class and I am just trying to implement a loop that goes through every file in a folder using os.listdir() and I specified that the folder is the given argv. I have been stuck on this problem for hours but I can't seem to figure out what the issue is.
The idea of my code is to "train" with a set of known goodware and known malware, then test it on a set of "unknown" files to see if it can correctly classify the files based on a specified feature; the final output should print the labels of the unknown files.
I have tried both the absolute and relative paths as my command line arguments thinking the issue could be related to accessing the subfolders, but that didn't fix the problem. [screenshot of code and directories][1]
commandline: python3 PEexample.py gw/ mw/ unknown/
Full error:
Traceback (most recent call last):
File "/Users/kyleefriederichs/Desktop/School/CSCE_698_CyberDefense/CSCE689_CyberDefense/Cyber_practice/PEexample.py", line 39, in <module>
pe1 = pefile.PE(file)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pefile.py", line 2895, in __init__
self.__parse__(name, data, fast_load)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pefile.py", line 2970, in __parse__
stat = os.stat(fname)
FileNotFoundError: [Errno 2] No such file or directory: 'gw1.exe'
idx_gw = 0
for file in os.listdir(sys.argv[1]):
# pe1=pefile.PE(file)
if not file.startswith("."):
try:
pe1 = pefile.PE(file)
except pefile.PEFormatError:
sys.exit("[-] Not PE file:" + file)
pe_gw_imps = len(pe1.DIRECTORY_ENTRY_IMPORT)
idx_gw += 1