All pastes #834849 Raw Edit

Untitled

public text v1 · immutable
#834849 ·published 2007-12-28 14:50 UTC
rendered paste body
#!/usr/bin/env python

import os

# Settings.
ShowTimestamp = False
ShowDirCount = False
ShowFileCount = False
ShowAverageFileSize = False
ShowTotalFileSize = False

def Traverse(Path):
	# Working values.
	global FileCount
	global DirCount
	global TotalFileSize
	# Get all children.
	try:
		Children = os.listdir(Path)
	except OSError, (errno, strerror):
		return
	for Child in Children:
		if os.path.isdir(Path + '/' + Child):
			DirCount += 1
			Traverse(Path + '/' + Child)
		elif os.path.isfile(Path + '/' + Child):
			FileCount += 1
			TotalFileSize += os.path.getsize(Path + '/' + Child)

def GetTimestamp():
	return "insert timestamp here"

def GetDirCount():
	return DirCount

def GetFileCount():
	return FileCount

def GetAverageFileSize():
	return TotalFileSize / FileCount

def GetTotalFileSize():
	return TotalFileSize

# Set initial global values.
FileCount = 0
DirCount = 0
TotalFileSize = 0

# Must not have trailing slash!
Traverse('/home/michael/Desktop')

print 'Timestamp =', GetTimestamp()
print 'Directory Count =', GetDirCount()
print 'File Count =', GetFileCount()
print 'Average File Size =', GetAverageFileSize()
print 'Total File Size =', GetTotalFileSize()