I need to write a code in python that can scan for all files inside a folder containing determined extensions like .exe, .jpg, .pdf.
Just like the linux command "ls | grep *.pdf"
I've tried to use a list containing all extensions i need and used Regular Expressions to search for it inside the folder. But i don't know what to put inside re.search()
I don't want to use something like "os" library because this script needs to work on Linux and Windows.
#!/usr/bin/python
import re
file_types = [".exe", ".jpg", ".pdf", ".png", ".txt"]
for line in file_types:
# Do something like "ls | grep * + line"
namefile = re.search(line, i_dont_know_what_to_put_here)
print(namefile)
Update: Thank guys for help, i used glob library and it's works!