sub traversePath($path) { ##DEBUG## print "\nDEBUG:traversing path '$path'\n"; ##DEBUG## # will contain combined filesize of all files in pwd $totalSize = 0; # convert any backslashes to fwdslashes $path =~ s/\\/\//g; # open up the current dir opendir(PATH,$path); # check for trailing slash and remove if found if(substr($path,-1,1) eq "/") {chop($path)} #read files & subdirs into @subdirs @subdirs = readdir(PATH); closedir(PATH); # loop through them all foreach $subdir (@subdirs) { # construct full pathname to current subdir or file $npath = $path."/".$subdir; # not a dir, just a file, perform a function # which returns the byte size of said file if(! -d $npath) { $totalSize += writeFile($npath); } # is a subdir else { # dont mess with cwd or parent dir if($npath ne "." && $npath ne "..") { ##DEBUG## print "\nDEBUG:npath='$npath'\n"; ##DEBUG## # call new instance of self and pass as param # to other function which records total bytesize # of directory writeDir($npath, traversePath($npath) ); } } } # return bytesize of any files found in current dir return $totalSize; }