• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 283
  • Last Modified:

getsize()

hi, i am trying to get the file size of files in the directories and sub directories ..... and i get this error
global name 'fs' is not defined ... and i dont need to use a global name .... any help will do thanks .....


def fsize():
   travFsize(fs)


def fileSize(a, dir, files):
   os.path.getsize(a)
   for fs in files:
      print dir, "Filesize = " + fs


def travFsize(fs):
   os.path.walk(fs, fileSize, None)
0
darrenteo82
Asked:
darrenteo82
  • 2
  • 2
1 Solution
 
RichieHindleCommented:
Here's a working example that prints the size of each file in your Windows directory:

import os

def fileSize(arg, dirname, names):
   for filename in names:
      filesize = os.path.getsize(os.path.join(dirname, filename))
      print dirname, filename, filesize

def travFsize(fs):
   os.path.walk(fs, fileSize, None)

travFsize("c:\\windows")
0
 
darrenteo82Author Commented:
i am wondering if you might know for the Unix directory ?
0
 
RichieHindleCommented:
It's exactly the same - just specify the directory in the last line:

travFsize("/home/darren")
0
 
ramromconsultant Commented:
darrenteo82 - does that do it for you?

Bob Gailer
Page Editor
0
 
ramromconsultant Commented:
As I read thru the list of abandoned questions I note the author of several is darrenteo82. I wonder what happened to him/her?
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now