Home > database >  Please help me in getting the output I want
Please help me in getting the output I want

Time:05-29

local = f"/home/server/Desktop/backupdestination/{year}/{month}/{date}/"
def a():
    size=0
    for root, dir_, files in os.walk(local):
      for f in dir_:
        fp = os.path.join(root, f)
        size  = os.path.getsize(fp)
    print(f" DATE {date} SERVER 1 Size is {size} " )

This gives me output like this , (8192)this is the combination of two folder)

DATE 26 SERVER 1 Size is 8192

I want the output to be like this(4096 is file size)

DATE 26 SERVER 1 Size is [foldername:4096 ,foldername: 4096]

CodePudding user response:

I tried this code:

import os

def a(local):
    sizes = []
    for root, dir_, files in os.walk(local):
        for f in dir_:
            fp = os.path.join(root, f)
            size = os.path.getsize(fp)
            sizes.append(f'{f}:{size}')

    print(f" DATE SERVER 1 Size is [{','.join(sizes)}] " )

a('.')

Sample output:

DATE SERVER 1 Size is [BG2:0,collatz:0,DragonTurtle:4096,Finance:0,FindBuild38:4096]
  • Related