Quick Search for:  in language:    
Uses,recursion,scan,directory,subdirectories,
   Code/Articles  |  Newest/Best  |  Community  |  Jobs  |  Other  |  Goto  | 
CategoriesSearch Newest CodeCoding ContestCode of the DayAsk A ProJobsUpload
PHP Stats

 Code: 107,779. lines
 Jobs: 40. postings

 How to support the site

 
Sponsored by:

 
You are in:
 

Does your code think in ink?
Login





Latest Code Ticker for PHP
Click here to see a screenshot of this code!Debug Window
By Hohl David on 12/30

(Screen Shot)

Click here to see a screenshot of this code!Add Google search technology to your site without Google branding.
By Sean Cannon on 12/29

(Screen Shot)

PHP System Function
By Ruben Benjamin on 12/29


Click here to see a screenshot of this code!MySQL GuestBook 1.0
By Uis on 12/27

(Screen Shot)

Click here to see a screenshot of this code!MySQL Guestbook
By Uis on 12/27

(Screen Shot)

Click here to see a screenshot of this code!MySQL Guestbook
By Uis on 12/27

(Screen Shot)

Click here to see a screenshot of this code!PHP Chat
By Kevin Harris on 12/25

(Screen Shot)

Preload whole directory of images
By Roland Osbeck on 12/23


Sessions
By Michael 'plasma' McMullen on 12/23


Click here to put this ticker on your site!


Add this ticker to your desktop!


Daily Code Email
To join the 'Code of the Day' Mailing List click here!

Affiliate Sites



 
 
   

Dir_Size - Recursively get the size of a directory

Print
Email
 
VB icon
Submitted on: 12/3/2003 1:11:47 AM
By: Daniel Green  
Level: Intermediate
User Rating: By 1 Users
Compatibility:PHP 4.0

Users have accessed this code 373 times.
 

 
     Uses recursion to scan a directory and all subdirectories to get the total size of all files residing within.
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
1) You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.   
2) You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
3) You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
4) You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.

    //**************************************
    //     
    // Name: Dir_Size - Recursively get the 
    //     size of a directory
    // Description:Uses recursion to scan a 
    //     directory and all subdirectories to get 
    //     the total size of all files residing wit
    //     hin.
    // By: Daniel Green
    //
    // Inputs:The only parameter is the root
    //     directory.
    //
    // Returns:Returns the total size of the
    //     directory and all contents.
    //
    // Assumes:Make sure you set $g_dirsize 
    //     = 0; before calling the function a secon
    //     d time.
    //
    //This code is copyrighted and has    // limited warranties.Please see http://
    //     www.Planet-Source-Code.com/vb/scripts/Sh
    //     owCode.asp?txtCodeId=1186&lngWId;=8    //for details.    //**************************************
    //     
    
    $g_dirsize = 0;
    function dir_size($dir)
    {
    	global $g_dirsize;
    	$handle = opendir($dir);
    	while($file = readdir($handle))
    	{
    		if($file != "." && $file != "..")
    		{
    			if(is_dir($dir . "/" . $file))
    			{
    				dir_size($dir . "/" . $file);
    			}else{
    				$g_dirsize += filesize($dir . "/" . $file);
    			}
    		}
    	}
    	return($g_dirsize);
    }


Other 2 submission(s) by this author

 

 
Report Bad Submission
Use this form to notify us if this entry should be deleted (i.e contains no code, is a virus, etc.).
Reason:
 
Your Vote!

What do you think of this code(in the Intermediate category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor See Voting Log
 
Other User Comments
12/4/2003 1:12:29 PM:
I haven't run this but my efforts 
recently weren't nearly as 
elegant.
See: 
http://www.phpbuilder.com/board/showthre
ad.php?s=&threadid;=10260472
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
Add Your Feedback!
Note:Not only will your feedback be posted, but an email will be sent to the code's author in your name.

NOTICE: The author of this code has been kind enough to share it with you.  If you have a criticism, please state it politely or it will be deleted.

For feedback not related to this particular code, please click here.
 
Name:
Comment:

 

Categories | Articles and Tutorials | Advanced Search | Recommended Reading | Upload | Newest Code | Code of the Month | Code of the Day | All Time Hall of Fame | Coding Contest | Search for a job | Post a Job | Ask a Pro Discussion Forum | Live Chat | Feedback | Customize | PHP Home | Site Home | Other Sites | About the Site | Feedback | Link to the Site | Awards | Advertising | Privacy

Copyright 1997 by Exhedra Solutions, Inc. All Rights Reserved.  By using this site you agree to its Terms and Conditions.  Planet Source Code (tm) and the phrase "Dream It. Code It" (tm) are trademarks of Exhedra Solutions, Inc.