Results 1 to 6 of 6

Thread: Size of a folder and all sub-folders...?

  1. #1

    Thread Starter
    Frenzied Member sciguyryan's Avatar
    Join Date
    Sep 2003
    Location
    Wales
    Posts
    1,763

    Size of a folder and all sub-folders...?

    Has anyone got a code that can get the size of a folder and all sub-folders - this is the last thing that I need and I've had no luck in solving it either.


    Thanks in advance for the help,

    RyanJ
    My Blog.

    Ryan Jones.

  2. #2
    Lively Member
    Join Date
    Dec 2004
    Location
    Canada
    Posts
    95

    Re: Size of a folder and all sub-folders...?

    Here is an idea,

    you could use the scandir() function to scan the folders for files, It will return an array with all of the files and then you could use the filesize() function to get the size of each file in the directory, which will give you the directory size.


    Ryan.

  3. #3
    Lively Member
    Join Date
    Dec 2004
    Location
    Canada
    Posts
    95

    Re: Size of a folder and all sub-folders...?

    maybe something like this:
    PHP Code:
    function getDirSize($dir) {
      IF (
    file_exists($dir)) 
         {
         
    $Files scandir($dir);

         For 
    0 To count($Files)
         {
           
    fSize filesize($files[i]);
         }
         return 
    fsize;

      } else {
        print 
    "Directory:" $dir "Does not exist";
      }

    Not: this code hasnt been tested, its mainly just to give you an idea, also scandir() function is only available in PHP5 i believe. But you can make your own custome one to suit your needs.

    EDIT: when looking at the scandir() function on php.net i found a custom scandir() function that a user submitted
    PHP Code:
    function scandir($dir$no_dots=FALSE) {

       
    $files = array();
       
    $dh  = @opendir($dir);
       if (
    $dh!=FALSE) {
           while (
    false !== ($filename readdir($dh))) {
               
    $files[] = $filename;
           }

           
    sort($files);

           if (
    $no_dots) {
               while((
    $ix array_search('.',$files)) > -1
                       unset(
    $files[$ix]);
               while((
    $ix array_search('..',$files)) > -1
                       unset(
    $files[$ix]);
           }
       }
       return 
    $files;

    Works with php 4.3.10
    Last edited by RyanEllis; May 17th, 2005 at 11:35 AM.

  4. #4

    Thread Starter
    Frenzied Member sciguyryan's Avatar
    Join Date
    Sep 2003
    Location
    Wales
    Posts
    1,763

    Re: Size of a folder and all sub-folders...?

    Yea, that could work - I'll try it later and let you know

    Cheers,

    RyanJ
    My Blog.

    Ryan Jones.

  5. #5
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: Size of a folder and all sub-folders...?

    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  6. #6

    Thread Starter
    Frenzied Member sciguyryan's Avatar
    Join Date
    Sep 2003
    Location
    Wales
    Posts
    1,763

    Re: Size of a folder and all sub-folders...?

    Quote Originally Posted by visualAd

    never heared of that function before, must have been added while I was not looking


    Cheers and thanks again,

    RyanJ
    My Blog.

    Ryan Jones.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width