Current location: Hot Scripts Forums » Programming Languages » Perl » Folder Size Script


Folder Size Script

Reply
  #1 (permalink)  
Old 04-19-04, 03:10 AM
StevieB StevieB is offline
Newbie Coder
 
Join Date: Jun 2003
Location: Scotland
Posts: 88
Thanks: 0
Thanked 0 Times in 0 Posts
Folder Size Script

Hi,

I'm trying to configure this script to check the folder file size.
Folder is "dazman"
Can anyone see anything glaringly obvious with this?

Code:
#!/usr/bin/perl

# print header
print "Content-type: text/html\n\n";

# Determine OS and set a seperator
$OS = $^O;
if($OS =~ /win/i) { $isWIN = 1; }
else {$isUNIX = 1;}
if($isWIN){ $S{S} = "\\\\"; }
else { $S{S} = "/";}

# enter starting point
my $size = &getServerSize("/home/sbremner/public_html/dazman");

# print size returned
print qq~Total size = $size~;

sub getServerSize {
	my ( %VAR, @folder, @dirs );
	
	$VAR{startAt} = shift;
	
	if($VAR{startAt}){
		$VAR{totalSize} = 0;
		$VAR{reading}	 = 1;
		$VAR{folder}		= $VAR{startAt};
		
		@dirs = ($VAR{folder});
		
		while($VAR{reading}){
			# remove current from server search
			$VAR{current} = shift(@dirs); 
			
			opendir(D, $VAR{current});
			@folder = readdir(D);
			closedir D;
			
			foreach(@folder) {
				unless($_ eq '.' || $_ eq '..') {
					if(-d "$VAR{current}$S{S}$_") {
						# add sub folders to server search
						push(@dirs, "$VAR{current}$S{S}$_"); 
					} else {
						$VAR{totalSize} += -s qq~$VAR{current}$S{S}$_~;
					}
				}
			}
			
			$VAR{reading} = 0 unless $dirs[0];
		}
	}
	
	$VAR{totalSize}	= $VAR{totalSize} / 1024;
	$VAR{totalSize}	= sprintf("%5.2f", $VAR{totalSize});
	$VAR{totalSize} =~ s/\s+//ig;
	1 while $VAR{totalSize} =~ s/(.*\d)(\d\d\d)/$1,$2/g;
	$VAR{totalSize} .= qq~kb~;
	return $VAR{totalSize};
Thanks guys!
__________________
Steve Bremner
Reply With Quote
  #2 (permalink)  
Old 04-18-05, 05:47 AM
Ajayp Ajayp is offline
New Member
 
Join Date: Apr 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Re:folder size script

hi,

Its nice code, as it removes the extra overhead otherwise required in the recursive method.

Regards,
Ajay

Last edited by Ajayp; 04-18-05 at 05:50 AM.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with my largest perl script. Grabbing data from a file. Sunnmann Perl 2 04-23-08 03:27 AM
Is there any integrity of script rankings? webmaster@atmanager.com Hot Scripts Forum Questions, Suggestions and Feedback 17 08-06-04 12:12 AM
will pay. php script needed. upload, resize, & email jamjammo Script Requests 4 02-29-04 08:30 PM
Affiliate script (PHP) whtiebear Job Offers & Assistance 2 12-21-03 12:12 AM
script bug - beginner (full source) optionalreaction Perl 4 12-15-03 05:33 PM


All times are GMT -5. The time now is 04:58 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.