Skip to content

Instantly share code, notes, and snippets.

@ShannonScott
Last active July 30, 2019 17:06
Show Gist options
  • Save ShannonScott/441601040f44b1e5d703dcf1ca34f957 to your computer and use it in GitHub Desktop.
Save ShannonScott/441601040f44b1e5d703dcf1ca34f957 to your computer and use it in GitHub Desktop.
[Python Walk File Tree] Walk a file tree in python. #python
import os
basepath = '/path/to/files'
extensions = ('.mp4', '.avi', '.mkv', '.mov')
for (dirpath, dirnames, filenames) in os.walk(basepath):
for filename in filenames:
basename, ext = os.path.splitext(filename)
if ext not in extensions:
continue
filepath = os.path.join(dirpath, filename)
print(filepath)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment