0

I'm using the following to get a list of files under the target directory

import os

output = []
pwd = os.getcwd()
print(pwd)
os.chdir("../../target_dir")
cmd = "find . -name \*svg"
os.system(cmd)

How do I get the list of files into output (list)?

Seanmc2
  • 67
  • 1
  • 6
  • Take a look at the [subprocess](https://docs.python.org/3/library/subprocess.html) module. – larsks Sep 02 '20 at 01:20
  • Side-note: Problems like this are usually better solved without resorting to external processes. `os.walk` and simple string tests could do this work in pure Python without resorting to launching external programs; unless the directory tree is absolutely massive, the cost of launching the external program and parsing its output is likely to exceed the actual cost of enumerating files, and it's far more error-prone due to the need to parse back from raw data (messing up when file names include whitespace is incredibly common). – ShadowRanger Sep 02 '20 at 01:29

0 Answers0