-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindexer.py
49 lines (45 loc) · 1.38 KB
/
indexer.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
# INDEXER - program to insert HTML index files in a directory tree
#
# Andrew Herbert 19/06/2020
import os.path
import sys
def fullName (path, name):
return path + '/' + name
def indexPath (path):
outfile = open (path + '/index.html', 'w')
outfile.write ('<html>\n')
outfile.write ('<body>\n')
outfile.write ('<table>\n')
filenames = os.listdir (path)
filenames.sort()
count = 0
for n in filenames:
if n.startswith ('.'):
continue
pn = fullName (path, n)
if n == 'index.htm' or n == 'index.html' or n == 'indexer.py':
continue
if count % 5 == 0:
outfile.write ('<tr>\n')
if os.path.isfile (pn):
outfile.write ('<td style="padding:10px"><a href="' +
n + '">' + n + '</a></td>\n')
if os.path.isdir (pn):
outfile.write ('<td style="padding:10px"><a href="' +
n + '/index.html">' + n + '</a></td>\n')
indexPath (pn)
if count % 5 == 4:
outfile.write ('</tr>\n')
count = count + 1
if count % 5 != 4:
outfile.write ('</tr>\n')
outfile.write ('</table>\n')
outfile.write ('</body>\n')
outfile.write ('</html>\n')
outfile.close ()
# Main program
if len (sys.argv) < 2:
indexPath ('.')
else:
path = sys.argv[1]
indexPath (path)