| 1 |
import argparse |
| 2 |
import os |
| 3 |
|
| 4 |
ap = argparse.ArgumentParser() |
| 5 |
ap.add_argument('path', nargs='+') |
| 6 |
opts = ap.parse_args() |
| 7 |
|
| 8 |
|
| 9 |
def gather(): |
| 10 |
for p in opts.path: |
| 11 |
if not os.path.exists(p): |
| 12 |
return |
| 13 |
if os.path.isdir(p): |
| 14 |
yield p + os.path.sep |
| 15 |
for dirpath, dirs, files in os.walk(p): |
| 16 |
for d in dirs: |
| 17 |
yield os.path.join(dirpath, d) + os.path.sep |
| 18 |
for f in files: |
| 19 |
yield os.path.join(dirpath, f) |
| 20 |
else: |
| 21 |
yield p |
| 22 |
|
| 23 |
|
| 24 |
print('\n'.join(sorted(gather(), key=lambda x: x.replace(os.path.sep, '/')))) |