473,378 Members | 1,527 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

How to get the given directory size?

Friends,

i want to calculate the size of the folders. Please give me some
suggestion in this.

thanks
Ganesh.G

Apr 24 '06 #1
2 1792
ma*************@gmail.com wrote:
Friends,

i want to calculate the size of the folders. Please give me some
suggestion in this.

thanks
Ganesh.G

The size of the folder = sum of size of files + sum of size of
subfolders. See:
dir - http://www.php.net/manual/en/ref.dir.php
fstat - http://www.php.net/manual/en/function.fstat.php
and a good tutorial on recursion.

-david-

Apr 24 '06 #2
NC
ma*************@gmail.com wrote:

i want to calculate the size of the folders. Please give me some
suggestion in this.


A directory is 4096 bytes long on most Unix versions. But, then,
your real question is not about the directory, it's about files in that

directory, right? If so, here's a possibility:

$dir = '/path/to/files';
$size = 0;
if ($handle = opendir($dir)) {
while (false !== ($file = readdir($handle))) {
$size = $size + filesize("$dir/$file");
}
closedir($handle);
}
echo "Total size of files in $dir: $size bytes";

For more information, see:

http://www.php.net/readdir
http://www.php.net/filesize

Note that the code above totals up only files in the
specified directory; files in subdirectories are ignored.

Cheers,
NC

Apr 24 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: francisl | last post by:
How can we get a full directory size (sum of all his data)? like when we type `du -sh mydir` Because os.path.getsize('mydir') only give the size of the directory physical representation on the...
1
by: Carolyn Speakman | last post by:
Hi, I need to get a directory listing from a client machine. The directory will be specified by the user and the results will be stored on the server in an xml file. I've been trying to use the...
17
by: Joe Laughlin | last post by:
I've not used C much before, so I don't know how robust or good this code is. I'd appreciate any feedback or criticisms anyone has! Thanks, Joe #include <stdio.h> #include <string.h>
11
by: F. Michael Miller | last post by:
I'd like to copy the listing of a directory (& sub directories) to a text file in vb.net. I'm looking for teh equivilant of the DOS command dir /s > TargetFile.txt. Thanks!
1
by: Microsoft | last post by:
Is there a way to to retrieve Directory Property information? I am trying to develop a way to monitor total Directory size say any directory over 200 meg. I have the logic to enumerate the...
2
by: LisaB | last post by:
I am new to Visual Basic .Net and would like to build a simple application that searches a directory and returns the Path, Size and DateModified of all files that end in ".MDB". a) I would...
2
by: Phil Galey | last post by:
Using the following, you can determine the size of a file: Dim fi As New IO.FileInfo(<Path to file>) MsgBox(fi.Length) .... but what about the size of a directory? The IO.DirectoryInfo object...
0
by: bcanter | last post by:
I found a file on the web that will allow you to enumerate groups but it was an .hta and the top level admins won't allow this. I need to give managers access to the groups so that when a new user is...
6
by: falconsx23 | last post by:
I am trying to write a code for a Phone Directory program. This program is suppose to allow the user to enter a name or directory and then program can either add, save or even delete an entry. Also...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.