I need it when it is a file it downloads and when it is a directory it accesses the directory, could anyone help me? because when I go to a folder it gets /Python/Python/directory and does not access, like leaving it only /python/directory
Thanks
#!/usr/bin/python
import web
import os
urls = (
'/(.*)', 'hello'
)
app = web.application(urls, globals())
class hello:
def GET(self, path):
path = '/Python/'+path
lista = '<html> <body>'
caminhos = [os.path.join(path, nome) for nome in os.listdir(path)]
diretorios = [dire for dire in caminhos if os.path.isdir(dire)]
for dire in diretorios:
# lista = lista+dire+'<br>'
lista = lista+'<a href='+dire+'>'+dire+'</a><br>'
arquivos = [arq for arq in caminhos if os.path.isfile(arq)]
for arq in arquivos:
lista = lista+'<a href='+arq+' target="_blank">'+arq+'</a><br>'
# lista = lista+arq+'<br>'
lista = lista+'<br><br><a href="javascript:window.history.go(-1)">Voltar</a></body> </html>'
return lista
if __name__ == "__main__":
app.run()