Megabtyes
-
- User
- Posts: 27
- Joined: Sun Jul 13, 2008 9:47 am
- Location: UK
Megabtyes
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
ie 12mb
Thanks
- Fluid Byte
- Addict
- Posts: 2336
- Joined: Fri Jul 21, 2006 4:41 am
- Location: Berlin, Germany
Yes. All you need is FileSize() and to know the fact that 1024kb are 1MB.
Windows 10 Pro, 64-Bit / Whose Hoff is it anyway?
There is an example in the Codearchiv:
dannyboy99 wants mbs
, so change the last line:
Debug Str(GetDirectorySize("C:\Windows\")/1024/1024) + " mbs"
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\")

Debug Str(GetDirectorySize("C:\Windows\")/1024/1024) + " mbs"
Sorry 4 my poor English, it's the only one I learned 40 years ago...
since 17.12.08: XPHome(SP3) + PB 4.30
since 17.12.08: XPHome(SP3) + PB 4.30
1024 Kibibyte = 1 MebibyteFluid Byte wrote:Yes. All you need is FileSize() and to know the fact that 1024kb are 1MB.
1000 KB = 1 MB
greetings
Thomas
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.

Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.

- Kaeru Gaman
- Addict
- Posts: 4826
- Joined: Sun Mar 19, 2006 1:57 pm
- Location: Germany
deeply sorry, but noone needs to accept some supid idea of some old farts who never wrote a single line of code.ts-soft wrote:1024 Kibibyte = 1 MebibyteFluid Byte wrote:Yes. All you need is FileSize() and to know the fact that 1024kb are 1MB.
1000 KB = 1 MB
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.
oh... and have a nice day.
Hi dannyboy99
Confused by all of this? (or just enjoying it too)?
try this one
http://en.wikipedia.org/wiki/Megabyte
cheers
Confused by all of this? (or just enjoying it too)?
try this one
http://en.wikipedia.org/wiki/Megabyte
cheers
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
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

- Kaeru Gaman
- Addict
- Posts: 4826
- Joined: Sun Mar 19, 2006 1:57 pm
- Location: Germany
@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.
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.
oh... and have a nice day.
-
- User
- Posts: 27
- Joined: Sun Jul 13, 2008 9:47 am
- Location: UK
Thanks
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.
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.
- Kaeru Gaman
- Addict
- Posts: 4826
- Joined: Sun Mar 19, 2006 1:57 pm
- Location: Germany
-
- User
- Posts: 27
- Joined: Sun Jul 13, 2008 9:47 am
- Location: UK
Hi
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
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
@dannyboy99: here's the code update to v4.20dannyboy99 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
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)
-
- User
- Posts: 27
- Joined: Sun Jul 13, 2008 9:47 am
- Location: UK
Thanks
Thanks very much for those who helped me here.
I have finsihed the programs, which seem to working well.
Thanks again
Danny
I have finsihed the programs, which seem to working well.
Thanks again
Danny
-
- User
- Posts: 27
- Joined: Sun Jul 13, 2008 9:47 am
- Location: UK
New coding
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
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