Advertisement
teslariu

dir

Sep 29th, 2022
1,117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.77 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. import os
  5. from datetime import datetime
  6. from tabulate import tabulate
  7.  
  8. directorio = "."
  9. tabla = []
  10.  
  11.  
  12. # escaneo el directorio
  13. for item in os.scandir(directorio):
  14.     info = item.stat()
  15.     ult_modificacion = datetime.utcfromtimestamp(info.st_mtime).strftime("%d/%m/%Y %H:%M")
  16.        
  17.     if item.is_file():
  18.         tamanio = info.st_size
  19.         tabla.append([ult_modificacion, "", tamanio, item.name])
  20.    
  21.     elif item.is_dir():
  22.         tabla.append([ult_modificacion, "<DIR>", "", item.name])
  23.        
  24. print(tabulate(
  25.             tabla,
  26.             headers = ["Fecha y hora", "Tipo", "Tamaño","Nombre"],
  27.             tablefmt = "plain",
  28.             colalign = ["center", "right", "right", "left"]
  29.     )
  30. )
  31.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement