Last active
March 12, 2022 06:43
-
-
Save fredrikaverpil/9761434 to your computer and use it in GitHub Desktop.
Walk folder and filter on filetype #python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os, fnmatch | |
startDirectory = 'C:/temp' | |
filetypes = ['*.jpg', '*.exr'] | |
for root, dirs, files in os.walk( startDirectory ): | |
for extension in ( tuple(filetypes) ): | |
for filename in fnmatch.filter(files, extension): | |
filepath = os.path.join(root, filename) | |
if os.path.isfile( filepath ): | |
# do something ... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
`import os, fnmatch
startDirectory = '/'
filetypes = ['.jpg', '.exe']
for root, dirs, files in os.walk( startDirectory ):
for extension in ( tuple(filetypes) ):
for filename in fnmatch.filter(files, extension):
filepath = os.path.join(root, filename)
print(os.path.join( filepath ))
# do something ...`