import os import json def file_name(file_dir): fileList =[] for root, dirs, files in os.walk(file_dir): fileList = files return fileList fileList = file_name(os.path.abspath('.')) f = open('filename.txt', 'w') for fn in fileList: if fn.split(".")[0] != "creatJsonProfile": f.write("'" + fn.split(".")[0] + "': 'assets/play/" + fn + "',\n") f.close()