Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- #
- import os
- from datetime import datetime
- from tabulate import tabulate
- directorio = input("Ingrese el directorio: ")
- # voy a mostrar archivos con tamaño y fecha de modificacion
- # creo una tabla para guardar los datos
- tabla = []
- for entrada in os.scandir(directorio):
- if entrada.is_file(): # pregunto si es un archivo
- info = entrada.stat() # almaceno el estado de un archivo
- tamaño = info.st_size
- if tamaño < 1024:
- tamaño = f"{tamaño} B"
- elif 1024 <= tamaño < 1024**2:
- tamaño = "{:.1f} KB".format(tamaño/1024)
- else:
- tamaño = "{:.1f} MB".format(tamaño / 1024**2)
- ult_modif = datetime.utcfromtimestamp(info.st_mtime).strftime("%d-%b-%y %H:%M")
- tabla.append([entrada.name, tamaño, ult_modif])
- print(tabulate(
- tabla,
- headers = ["Archivo", "Tamaño", "Ultima modificación"],
- tablefmt = "grid",
- colalign = ['left', 'right', 'center']
- )
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement