So i have a python code that searches for a folder in a directory and gets the size of the folder. I am wanting to search inside the folder and get the file size of what is in the folder. The items in the folder will have different extentions so if there is any way to do this it would be a great help.

import requests, shutil, datetime, glob, os, csv,fnmatch,StringIO,smtplib,argparse
from email.MIMEMultipart import MIMEMultipart
from email.MIMEText import MIMEText
from os import path

parser = argparse.ArgumentParser(description='Search art folders.')
parser.add_argument('-b', help='The base path', required=False, dest='basePath', metavar='Base directory path',default='/home/hatterx/Desktop')
parser.add_argument('--se', help='Change sending emailaddress', required=False, dest='sendEmail', metavar='Sending Emailaddress', defauault='hatterx2031@yahoo.com')
parser.add_argument('--re', help='Change reciveing emailaddress', required=False,dest='reciveEmail', metavar='Reciveing Emailaddress', default='abaddon2031@gmail.com')
parser.add_argument('--pw', help='Change password', required=False, dest='changePassword', metavar='Change Password', default='jcfutalhndkwsltg')
parser.add_argument('-s', help='Change File size', required=True, dest ='changesize', metavar='Change size', default='0')
parser.add_argument('-S', help='Change File Size', required=True, dest ='changeSize', metavar='Change Size', default='0')
args = parser.parse_args()

fF = datetime.datetime.now().strftime("%Y%B")
fA = datetime.datetime.now().strftime("%Y%b")

filebase = args.basePath
fileFull = filebase+'/'+fF.upper()+'JPG/*'
fileAbriv = filebase+'/'+fA.upper()+'JPG/*'
Reciver = args.reciveEmail
Sender = args.sendEmail
Password = args.changePassword

size = path.getsize(fileFull)

Size = path.getsize(fileAbriv)

SUBJECT = 'File size of '+fileFull
Subject = 'File size of '+fileAbriv
BODY = 'The file size of '+fileFull+' was greater than '+str(size)+'.'
Body = 'The file size of '+fileAbriv+' was greater than '+str(Size)+'.'

if args.changesize >= str(size):
    sendEmail(args.reciveEmail, SUBJECT, BODY)
    print (size)
    print (fileFull)

if args.changeSize >= str(Size):
    sendEmail(args.reciveEmail, Subject, Body)
    print (Size)
    print (fileAbriv)

Edited by abaddon2031: forgot to add my code in the original post

2 Years
Discussion Span
Last Post by ~s.o.s~

You will have to use a recursive algorithm to compute the size of a folder including all the files and sub-directories (and again all the files in that sub-directory). Use suggestions from this thread for that recursive function. Also, don't use string concatenation for path creation, use os.path.join for that.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.