-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconf.py
More file actions
38 lines (35 loc) · 913 Bytes
/
Copy pathconf.py
File metadata and controls
38 lines (35 loc) · 913 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# coding:utf8
import json
import sys,os
#格式化json文件
def getFileCon(filename):
if not os.path.isfile(filename):
return
with open(filename, "r") as f:
con = f.read()
f.close()
return con
def writeFile(filepath,con):
with open(filepath, "w") as f:
f.write(con)
f.close()
if __name__ == "__main__":
booknotedir=os.path.expanduser('~')+"/Documents/BookNotes"
os.chdir(booknotedir)
fl = []
for p,d,file in os.walk(os.getcwd()):
for f in file:
fl.append(os.path.join(p,f))
for f in fl:
g = f
if not f.endswith(".json"):
continue
try:
#print(f)
con = json.loads(getFileCon(f))
# print con
# writeFile(f,json.dumps(con,indent=4,ensure_ascii=False).decode('utf8'))
writeFile(f,json.dumps(con,indent=4,ensure_ascii=False))
print (g,'OK')
except Exception as e:
print (g,'is not json format')