Page 1 of 2
Megabtyes
Posted: Fri Aug 08, 2008 7:38 pm
by dannyboy99
Is there a way I can use a gedgetbox? to show the total size of the files in a directory, but put the result in letters
ie 12mb
Thanks
Posted: Fri Aug 08, 2008 8:09 pm
by Fluid Byte
Yes. All you need is FileSize() and to know the fact that 1024kb are 1MB.
Posted: Fri Aug 08, 2008 8:35 pm
by harff182
There is an example in the Codearchiv:
Code: Select all
Procedure.q GetDirectorySize(path.s, size.q=0)
Protected dir.l=ExamineDirectory(#PB_Any, path, "")
If dir
While NextDirectoryEntry(dir)
If DirectoryEntryType(dir) = #PB_DirectoryEntry_File
size+DirectoryEntrySize(dir)
ElseIf Not DirectoryEntryName(dir) = "." And Not DirectoryEntryName(dir) = ".."
GetDirectorySize(path+DirectoryEntryName(dir)+"\", size)
EndIf
Wend
FinishDirectory(dir)
EndIf
ProcedureReturn size
EndProcedure
Debug GetDirectorySize("C:\Windows\")
dannyboy99 wants mbs

, so change the last line:
Debug Str(GetDirectorySize("C:\Windows\")/1024/1024) + " mbs"
Posted: Fri Aug 08, 2008 8:57 pm
by ts-soft
Fluid Byte wrote:Yes. All you need is FileSize() and to know the fact that 1024kb are 1MB.
1024 Kibibyte = 1 Mebibyte
1000 KB = 1 MB
greetings
Thomas
Posted: Fri Aug 08, 2008 9:32 pm
by Kaeru Gaman
ts-soft wrote:Fluid Byte wrote:Yes. All you need is FileSize() and to know the fact that 1024kb are 1MB.
1024 Kibibyte = 1 Mebibyte
1000 KB = 1 MB
deeply sorry, but noone needs to accept some supid idea of some old farts who never wrote a single line of code.
1GB = 1024 MB
1 MB = 1024 KB
1 KB = 1024 Byte
if they insist in the meaning of their beloved Kilo, they should write kB with a small k if they mean 1000byte.
realize, a bunch of old farts could say whatever they want - only if people follow it will become true (or can even try to become true)
most people in the world have not the merest idea in MB and KB,
so what they believe depends on what they are told.
and who talk to them about memory sizes more often -
the old farts, the press who publish the old farts, or the millions
and millions of hobby programmers all around the world?
just ignore that bullshit, and they would forget it if it never gets common enough.
Posted: Fri Aug 08, 2008 10:02 pm
by Marco2007
Kaeru Gaman wrote:1 KB = 1024 Byte
What`s correct?
1KB = 1024 Byte
or
1KB = 1024 Bytes?
lg
Marco
Posted: Fri Aug 08, 2008 10:10 pm
by rsts
Hi dannyboy99
Confused by all of this? (or just enjoying it too)?
try this one
http://en.wikipedia.org/wiki/Megabyte
cheers
Posted: Fri Aug 08, 2008 10:21 pm
by Chirantha
8 bits = 1 Byte
1024 Bytes = 1 Kilo-Byte
1024 Kilo-Bytes = 1 Mega-Byte
1024 Mega-Bytes = 1 Giga-Byte
1024 Giga-Bytes = 1 Triga-Byte
1024 Triga-Bytes = 1 Pica-Byte
1024 Pica-Bytes = 1 Yota-Byte
1024 Yota-Bytes = 1 Zita-Byte
*Names can be incorrect
Using a 8 byte number you can calculate the file/folder size upto 16 Yota-Bytes

Posted: Sat Aug 09, 2008 3:38 am
by Kaeru Gaman
@rsts
thanx for the Wiki-link, never would have looked there without you posting it.
... and I learned something new: didn't know they called 1000KB a Megabyte on a floppy.
and seems the industry started calling 10^9byte a Gigabyte, for selling purposes.
maybe the old farts only stated the binary prefixes to make the industry stop that bullshit?
dunno.
Thanks
Posted: Sat Aug 09, 2008 12:27 pm
by dannyboy99
Thanks for all your help.
Last question I promise, (well I hope).
I needed this info because I am trying to write a program that using a progress bar will show the amount of space left on a hard drive - similar to the pie chart you see in Windows properties.
Does PB have a way of counting up all the files, and displaying the total file size as one number, and can it tell me the size of the hard disk.
Posted: Sat Aug 09, 2008 12:48 pm
by Kaeru Gaman
I think there is an OS-function to request the remaining space of a hard drive...
> Does PB have a way of counting up all the files, and displaying the total file size as one number
you can write a recursive routine, but it would take quite some time to execute...
Hi
Posted: Sat Aug 09, 2008 5:40 pm
by dannyboy99
I found this on the web, and to honest it is totally out of my league, but when I run it it says
Structure "Interface" or "Prototype" already declared Quad - any idea pse
drive.s = "C:\"
Structure Quad
L1.l
L2.l
EndStructure
GetDiskFreeSpaceEx_(@drive, FB.Quad, TB.Quad, TFB.Quad)
If TB\L1 & $80000000
TB\L1 & $7FFFFFFF
TB\L1>>20
TB\L1 + $800
TB\L2<<12
Else
TB\L1>>20
TB\L2<<12
EndIf
TotalMB.l = TB\L1 + TB\L2
If TFB\L1 & $80000000
TFB\L1 & $7FFFFFFF
TFB\L1>>20
TFB\L1 + $800
TFB\L2<<12
Else
TFB\L1>>20
TFB\L2<<12
Re: Hi
Posted: Sat Aug 09, 2008 6:40 pm
by Demivec
dannyboy99 wrote:I found this on the web, and to honest it is totally out of my league, but when I run it it says
Structure "Interface" or "Prototype" already declared Quad - any idea pse
drive.s = "C:"
Structure Quad
L1.l
L2.l
EndStructure
GetDiskFreeSpaceEx_(@drive, FB.Quad, TB.Quad, TFB.Quad)
If TB\L1 & $80000000
TB\L1 & $7FFFFFFF
TB\L1>>20
TB\L1 + $800
TB\L2<<12
Else
TB\L1>>20
TB\L2<<12
EndIf
TotalMB.l = TB\L1 + TB\L2
If TFB\L1 & $80000000
TFB\L1 & $7FFFFFFF
TFB\L1>>20
TFB\L1 + $800
TFB\L2<<12
Else
TFB\L1>>20
TFB\L2<<12
@dannyboy99: here's the code update to v4.20
Code: Select all
drive.s = "C:"
GetDiskFreeSpaceEx_(@drive, @FB.q, @TB.q, @TFB.q)
Debug drive
Debug FB ;free bytes available to user
Debug TB ;total bytes
Debug TFB ;total free bytes
Debug TB >> 20 ;total in MB (1024x1024 bytes)
Thanks
Posted: Thu Aug 21, 2008 6:55 pm
by dannyboy99
Thanks very much for those who helped me here.
I have finsihed the programs, which seem to working well.
Thanks again
Danny
New coding
Posted: Sun Aug 24, 2008 11:57 am
by dannyboy99
I spoke to soon, I will have to rewrite the program
They now want a progress bar to show used/unused disk space
harff182 can you please tell me where to change the drive letter in your coding so I can select the drive to check.
I was going to use the super duper code for total disk space, but they would prefer to keep it simple, so unless there is a very simple bit of code I think the best idea is just to have the total disk size as a fixed variable (i will use dos to find the total disk size.
Thanks
Danny