Skip to content

Instantly share code, notes, and snippets.

@easternnl
Created June 19, 2020 13:03
Show Gist options
  • Save easternnl/b2a1380013eea990db7413de8b58d4fe to your computer and use it in GitHub Desktop.
Save easternnl/b2a1380013eea990db7413de8b58d4fe to your computer and use it in GitHub Desktop.
Python file list convert to JSON with MTime included (and other properties if needed)
import os, json
class FileItem(dict):
def __init__(self, name):
dict.__init__(self, name=name)
dict.__init__(self, mtime=os.path.getmtime(name)) # get the modify time
my_objects = []
for root, dirs, files in os.walk("./JMeterReplaceAllVariabelesInVar/", topdown=False):
files = [ fi for fi in files if fi.endswith(".groovy") ]
for name in files:
#print(os.path.join(root, name))
my_objects.append(FileItem(os.path.join(root, name)))
#for name in dirs:
# print(os.path.join(root, name))
#a = my_objects.toJSON
a = json.dumps(my_objects)
print("Wait")
# later
for obj in my_objects:
print (obj['fname'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment