dir_files = []This gets all of the filenames relative to "target" - so if we are in /something/, the file "/something/target/my_directory/my_file" will be listed as "my_directory/my_file".
for root, dirs, filenames in os.walk("target"):
for filename in filenames:
path = os.path.join(root, filename)
rel_path = os.path.relpath(path, "target")
dir_files.append(rel_path)
Of course, this can be done with list comprehensions as well but I left it in loop form because I think that's more readable.
No comments:
Post a Comment