• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

python check OTS folder information

miguelshta

Member
Joined
Mar 21, 2009
Messages
351
Solutions
1
Reaction score
13
Location
Toronto, Canada
Hello im trying to make a python code to automate my report i check my OTS folder every 7-15 days for space etc+ i always run a command to extract all files info and i paste it in a excel sheet but it takes time and i wanted to automate this so im trying to create table to find files information in the folder im new to python and i didnt know how to extract each value on excel is easy with filters but dont wanna waste time on it anymore.
Explaniation on:
First entry: here i wanted to get the oldest file date
Last Entry: i need to get the newest file date
Total Count: get total files in the folder
Average MBs: i need to get average size of the files in mbs
MaxMB: need to get the biggest file size
MinMB: need to get smaller file size
MidMB: the medium size
size for 6 months: calculate how much space ill need for 6 months
size 1 year: = size6months*2

Python:
from prettytable import PrettyTable
import os
import datetime

def ts_to_dt(ts):
    return datetime.datetime.fromtimestamp(ts)

for item in os.scandir():
     print(item.name, item.path, item.stat().st_size, ts_to_dt(item.stat().st_atime))

firstE = "12/07/2012"
lastE = ts_to_dt(item.stat().st_atime)
totalC = "206"
avgMb = "5"
maxMb = "15"
minMb = "1"
medMb = "10"
size6 = "8"
size12 = "16"
customer = "Windows"
instance = "Azure20"

x = PrettyTable()
x.field_names = ["First Entry", "Last Entry", "Total Count", "Avg Mb size", "Max mb size", "Min mb size", "Med mb size", "size 6 months", "size 1 year", "Customer", "Instance" ]
x.add_row([ (firstE), (lastE), (totalC), (avgMb), (maxMb), (minMb), (medMb), (size6), (size12), (customer), (instance)])
print(x)
 
Back
Top