#!/usr/bin/env python3 import sys, os, re, datetime, locale webbasedir = os.path.expanduser("~/Media") ### for module mkdirindex: targetdir = webbasedir + "/Videos" indexfilename = "index.html" targetdirheadline = "Something." showsize = 0 #### def mkdirindex(targetdir, indexfilename, targetdirheadline, showsize): """Dig a directory and generate an index.""" head1 = ( '\n \n' + targetdirheadline + '\n \n \n ' ) style_fn = '' head2 = "" body1 = 'Main

' body1 += '
' + targetdirheadline + "
" body1 += '' foot = '

Some byebye

\n' linecounter = 0 dirindexfile = open(targetdir + indexfilename, "w") dirindexfile.write(head1 + style_fn + head2 + body1) sortedtargetdir = os.listdir(targetdir) sortedtargetdir.sort() sortedtargetdir.reverse() for file in sortedtargetdir: sizestr = "" # If showsize is 1 we have some filesdir and want to see the size of a file if not re.match("^\.", file) and not file == indexfilename: if showsize == 1: size = os.lstat(targetdir + file).st_size if size > 100000000000: sizestr = str(int(size / 1073741824)) + " GiB" elif size > 100000000: sizestr = str(int(size / 1048576)) + " MiB" elif size > 10000: sizestr = str(int(size / 1024)) + " KiB" else: sizestr = str(size) + " B" else: entryname = re.sub(".html$", "", file) # entryname = re.sub(".html$", "", re.sub("[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9] [0-2][0-9]:[0-6][0-9] ", "", file)) line = str('' + entryname + " " + sizestr + "") dirindexfile.write(line) linecounter += 1 dirindexfile.write(foot) return linecounter # Dig the files-directory and generate an index. linecounter = mkdirindex(targetdir, indexfilename, targetdirheadline, showsize) print("Dirindex in ", targetdir, " has ", linecounter, "lines") # Have a nice time.