Skip to content

Instantly share code, notes, and snippets.

@dtaivpp
Last active December 16, 2019 13:48
Show Gist options
  • Select an option

  • Save dtaivpp/2641f3c141199ae426e48af878a0eca6 to your computer and use it in GitHub Desktop.

Select an option

Save dtaivpp/2641f3c141199ae426e48af878a0eca6 to your computer and use it in GitHub Desktop.
Iterate a directory looking for certain TypeScript and JavaScript files
import os
walk_dir = 'C:\\Directory\\ForWalking\\'
# If the file path contains these we dont want them
# eg. C:\\Directory\\ForWalking\\node_modules will be ignored
exclusions = ["node_modules", "SolutionFiles", ".bin", "Test"]
# Array to store all our file paths
file_paths = []
# Iterate file tree
for root, sub_dirs, file_names in os.walk(walk_dir):
# Iterate the file names in the directory
for file_name in file_names:
# We only are interested in Typscript and JS Files
if file_name.endswith(".ts")
or file_name.endswith(".tsx")
or file_name.endswith(".js"):
# If the file path doesnt have
# anything from the exclusion list
if not any(exclusion in root for exclusion in exclusions):
file_paths.append(os.path.join(root, file_name))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment