1. How to get the total size of a given folder...
- Posted by Matteo <matt1 at MEDIACOM.IT>
Dec 27, 1998
-
Last edited Dec 28, 1998
Hi to everyone.
I have a problem: I have to know the total size of a folder, I mean the sum
of the size of all its files and of its possible subfolders...
I hope someone has an "already coded" solution! :)
Bye,
Matt
2. How to get the total size of a given folder...
Use dir. A sequences of sequences will be returned. Each element
describes a directory entry.
for i = 1 to directory do -- directory = dir()
size = size+directory[i][3] -- where size was initialized to 0
end for
For each entry, find('d',directory[i]). If not zero, then change to each
sub and do it recursively. There are a few kinks, but this should get you
started. Its actually not hard.
Alan
3. Re: How to get the total size of a given folder...
- Posted by Daniel Berstein <daber at PAIR.COM>
Dec 27, 1998
-
Last edited Dec 28, 1998
At 05:08 p.m. 27-12-98 , you wrote:
>Use dir. A sequences of sequences will be returned. Each element
>describes a directory entry.
>
>for i = 1 to directory do -- directory = dir()
> size = size+directory[i][3] -- where size was initialized to 0
>end for
>
>For each entry, find('d',directory[i]). If not zero, then change to each
>sub and do it recursively. There are a few kinks, but this should get you
>started. Its actually not hard.
More complete:
include file.e
function DirSize(sequence DirName)
object directory
integer size
size = 0
directory = dir(DirName)
if atom(directory) then
-- No file or directory
return -1
end if
for i = 1 to length(directory) do
if find('d', directory[i][D_ATTRIBUTES]) then
-- If directory then call recursivly
size = size + DirSize(DirName & "\\" &
directory[i][D_NAME])
else
size = size + directory[i][D_SIZE]
end if
end for
return size
end function
Regards,
Daniel Berstein
daber at pair.com
4. Re: How to get the total size of a given folder...
Hi Daniel,
I discovered a small but nasty bug in your code. Upon running it, it kept
recursing, because of the directory names '.' and '..'. So I've added
another test for this, and now it runs smoothely.
Ad
new email adress: kwibus at dolfijn.nl
include file.e
function DirSize(sequence DirName)
object directory
integer size
size = 0
directory = dir(DirName)
if atom(directory) then
-- No file or directory
return -1
end if
for i = 1 to length(directory) do
if find('d', directory[i][D_ATTRIBUTES]) then
if not find('.', directory[i][D_NAME]) then -- added this line
-- If directory then call recursivly
size = size + DirSize(DirName & "\\" &
directory[i][D_NAME])
end if -- and this, of course
else
size = size + directory[i][D_SIZE]
end if
end for
return size
end function
-- Test:
-- ? DirSize("C:\\Euphoria\\projects")
5. Re: How to get the total size of a given folder...
Your right Ad! was a simple typo!
> for i = 1 to length(directory) do
^^^^
Should be 3
> if find('d', directory[i][D_ATTRIBUTES]) then
> if not find('.', directory[i][D_NAME]) then -- added this line
I was coding it on dos box with ed and then re type it on Eudora.
Thinking it twice... mmhh.. your adition will fail if I have any
subdirectory with a period on it's name, and my typo wouldn't help that
much if the directory is empty.
Solution:
include file.e
function DirSize(sequence DirName)
object directory
integer size
size = 0
directory = dir(DirName)
if atom(directory) then
-- No file or directory
return -1
end if
-- If it is a directory it will have "." and ".." entries
if length(directory) > 3 then -- Added this line, dir empty else
for i = 3 to length(directory) do
if find('d', directory[i][D_ATTRIBUTES]) then
-- If directory then call recursivly
size = size + DirSize(DirName & "\\" &
directory[i][D_NAME])
else
size = size + directory[i][D_SIZE]
end if
end for
end if -- An this, of course
return size
end function
Regards,
Daniel Berstein
daber at pair.com
6. Re: How to get the total size of a given folder...
actually dos has an answer
do a "DIR /S" on the folder and the total will be displayed
7. Re: How to get the total size of a given folder...
- Posted by Arthur Adamson <euclid at ISOC.NET>
Dec 28, 1998
-
Last edited Dec 29, 1998
At 12:19 PM 12/28/98 +0000, Thys de Jong wrote:
>actually dos has an answer
>
>do a "DIR /S" on the folder and the total will be displayed
>
BTW, Thys, better use DIR /s/a to pick up the system and hidden
files. Else the usage is understated.
In a small partition, I get:
Used Bytes Allocated Bytes
dos 6.21
dir /s 8226469
dir /s/a 8346165
My 4dos gives
dir /s 8226469 8445952
dir /s/a 8346155 8566784
My disk scanner, ds421b gives:
8577024
I assume the differences are due to different treatment of fat
tables, dir storage, etc.
Bye, Art
Arthur P. Adamson, The Engine Man, euclid at isoc.net
8. Re: How to get the total size of a given folder...
- Posted by Hendy Irawan <ceefour at INDO.NET.ID>
Dec 30, 1998
-
Last edited Dec 31, 1998
Desember 1998...
> My 4dos gives
Where can I get it?
Anyways dir/s/a won't give you files in hidden folders (try to do it
in C:\Temporary Internet Files\ for those using IE !)
Don't forget to reply, Euphoria,
C4 => Phone: +62 (354) 685866
Investment in reliability increases until it exceeds the probable cost of
errors, or until someone insists on getting some useful work done.
Try this...
Search Mailing Lists
http://www.liszt.com