Advertisement
teslariu

dir en python

Jan 16th, 2023
1,213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.79 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. #
  3. import os
  4. from datetime import datetime
  5. from tabulate import tabulate
  6.  
  7. directorio = "."
  8. tabla = []
  9.  
  10. print(f"Directorio de {os.getcwd()}\n")
  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