Advertisement
teslariu

escaneo archivos

Apr 12th, 2022
1,207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.87 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. # python -m pip install tabulate
  5. import os
  6. from datetime import datetime
  7. from tabulate import tabulate
  8.  
  9. directorio = input("Ingrese el directorio: ")
  10.  
  11. # vamos a mostrar archivos con tamaño y fecha de ult modificacion
  12. tabla = []
  13. for entrada in os.scandir(directorio):
  14.     if entrada.is_file():
  15.         info = entrada.stat()
  16.         tam = info.st_size
  17.        
  18.         if tam < 1024:
  19.             tam = f"{tam} B"
  20.            
  21.         elif 1024 <= tam < 1024**2:
  22.             tam = tam/1024
  23.             tam = f"{tam:.1f} KB"
  24.            
  25.         else:
  26.             tam = tam/1024**2
  27.             tam = f"{tam:.1f} MB"
  28.            
  29.         ult_mod = datetime.utcfromtimestamp(info.st_mtime).strftime("%d-%b-%y %H:%M")
  30.         tabla.append([entrada.name, tam, ult_mod])
  31.        
  32. print(tabulate(
  33.             tabla,
  34.             headers = ["Archivo", "Tamaño", "Ultima modificacion"],
  35.             tablefmt = "rst",
  36.             colalign = ["left", "right", "center"]
  37.             )
  38.     )
  39.        
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement