File size: 827 Bytes
8f3f8db
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
# walk directory tree and create sqindex.json files
from __future__ import with_statement

import sys, os, stat, json

sqindex = "sqindex.json"

def mksqindex(dirpath):
    print(dirpath)
    dir = []
    for name in os.listdir(dirpath):
        if name[0] == '.' or name == sqindex:
            continue
        path = os.path.join(dirpath, name)
        dirflag = os.path.isdir(path)
        ctime = int(os.path.getctime(path)) + 2177427600
        mtime = int(os.path.getmtime(path)) + 2177427600
        size = 0 if dirflag else os.path.getsize(path)
        dir.append([name, ctime, mtime, dirflag, size])
        if dirflag:
            mksqindex(path)
    with open(os.path.join(dirpath, sqindex), 'w') as f:
        json.dump(dir, f, indent = 0, separators = (',', ': '))

mksqindex(sys.argv[1])