Last active
June 9, 2020 10:12
-
-
Save black-black-cat/7a7a7ef439dde451560d1f6a400b6516 to your computer and use it in GitHub Desktop.
directory iterating
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import pathlib | |
import json | |
maindir = os.path.join(os.getcwd(), '..') | |
dirs = [os.path.join(maindir, dir) for dir in os.listdir(maindir)] | |
package_names = [] | |
for dir in dirs: | |
f = os.path.join(dir, 'package.json') | |
try: | |
f = open(f, 'r') | |
content = f.read() | |
dict = json.loads(content) | |
package_name = dict['name'] | |
package_names.append(package_name) | |
except: | |
pass | |
print(json.dumps(package_names, indent=4, sort_keys=True)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment