-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathserver.py
51 lines (43 loc) · 1.16 KB
/
server.py
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
39
40
41
42
43
44
45
46
47
48
49
50
51
from flask import Flask,jsonify
import os
app = Flask(__name__)
app.config['JSON_SORT_KEYS']=False
def scan(path):
files=[]
try:
currentdir= os.listdir(path)
for f in currentdir:
if f.startswith('.') or f==="desktop.ini":
continue
if os.path.isdir(path+'/'+f):
a={
'name':f,
'type':'folder',
'path':path+'/'+f,
'items': scan(path+'/'+f),
}
files.append(a)
else:
a = {
'name': f,
'type': 'file',
'path': path+'/'+f,
'size':os.path.getsize(path+'/'+f)
}
files.append(a)
except:
print("")
return files
@app.route('/<path>')
def hello_world(path):
os.chdir('C:/'+path)
dir=scan('.')
response={
'name':path,
'type':'folder',
'path':path,
'items':dir
}
return jsonify(response)
if __name__ == '__main__':
app.run()