[ad_1]
My code in order till the line.
drives = [ chr(x) + ":\\" for x in range(65,91) if os.path.exists(chr(x) + ":\\") ]
I see all the extentions of files in a specified disk with this code block
ListFiles = os.walk("d:\\") #normally putting drives here. and getting an error.
SplitTypes = []
for walk_output in ListFiles:
for file_name in walk_output[-1]:
SplitTypes.append(file_name.split(".")[-1])
print(SplitTypes)
with this
counter = 0
inp = SplitTypes
for drive in drives:
for r, d, f in os.walk(drive):
for file in f:
filepath = os.path.join(r, file)
if inp in file:
counter += 1
print(os.path.join(r, file))
print(f"counted {counter} files.")
Second code block prints out all the file’s extentions such as: txt, png, exe, dll etc. \
Example:
['epr',itx', 'itx', 'ilut', 'itx', 'itx', 'cube', 'cube', 'cube', 'itx', 'cube', 'cube''js','dll', 'dll', 'dll', 'json', 'json', 'json', 'json', 'json', 'json', 'json', 'json', 'json', 'json''rar', 'rar', 'ini', 'chm', 'dll', 'dll', 'dll', 'exe', 'sfx', 'sfx', 'exe', 'exe', 'ion', 'txt', 'txt', 'txt', 'exe', 'txt', 'txt', 'txt', 'txt',
'txt', 'txt', 'txt',]
The problem I’m facing here is I can’t scan for extensions in all drivers (second block of code).
And I can’t search all the files with the extensions that (second block of code) provided to third block of code.
For better Understanding you can think like this is an antivirus doing a complete scan on your PC.
[ad_2]