Megabtyes

Just starting out? Need help? Post your questions and find answers here.
dannyboy99
User
User
Posts: 27
Joined: Sun Jul 13, 2008 9:47 am
Location: UK

Megabtyes

Post 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
User avatar
Fluid Byte
Addict
Addict
Posts: 2336
Joined: Fri Jul 21, 2006 4:41 am
Location: Berlin, Germany

Post by Fluid Byte »

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?
harff182
Enthusiast
Enthusiast
Posts: 105
Joined: Thu Dec 08, 2005 4:58 pm
Location: Duesseldorf, Germany

Post 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 :lol:, so change the last line:
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
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Post 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
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.
Image
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post 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.
oh... and have a nice day.
Marco2007
Enthusiast
Enthusiast
Posts: 648
Joined: Tue Jun 12, 2007 10:30 am
Location: not there...

Post by Marco2007 »

Kaeru Gaman wrote:1 KB = 1024 Byte

What`s correct?

1KB = 1024 Byte
or
1KB = 1024 Bytes?

lg
Marco
Last edited by Marco2007 on Fri Aug 08, 2008 10:15 pm, edited 1 time in total.
PureBasic for Windows
rsts
Addict
Addict
Posts: 2736
Joined: Wed Aug 24, 2005 8:39 am
Location: Southwest OH - USA

Post by rsts »

Hi dannyboy99

Confused by all of this? (or just enjoying it too)?

try this one

http://en.wikipedia.org/wiki/Megabyte

cheers
Chirantha
User
User
Posts: 54
Joined: Sat Jul 16, 2005 7:22 pm

Post 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 :oops:

Using a 8 byte number you can calculate the file/folder size upto 16 Yota-Bytes :)
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post 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.
oh... and have a nice day.
dannyboy99
User
User
Posts: 27
Joined: Sun Jul 13, 2008 9:47 am
Location: UK

Thanks

Post 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.
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post 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...
oh... and have a nice day.
dannyboy99
User
User
Posts: 27
Joined: Sun Jul 13, 2008 9:47 am
Location: UK

Hi

Post 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
User avatar
Demivec
Addict
Addict
Posts: 4260
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: Hi

Post 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)
dannyboy99
User
User
Posts: 27
Joined: Sun Jul 13, 2008 9:47 am
Location: UK

Thanks

Post by dannyboy99 »

Thanks very much for those who helped me here.

I have finsihed the programs, which seem to working well.

Thanks again

Danny
dannyboy99
User
User
Posts: 27
Joined: Sun Jul 13, 2008 9:47 am
Location: UK

New coding

Post 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
Post Reply