473,657 Members | 2,776 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Format filesize in kB or MB

Hello,

When I have read a file with x.xxx.xxx.xxx bytes it is sometimes handy to
show it in an diverent format than bytes.

Is there a handy way to do this?
Or is there a function for it?

When it is a big file I want to see a MB size and when it is a lower file
size then I want to see a kB size for example.

Thanks!
Nov 17 '05 #1
3 3385
It shouldn't be too much trouble to do it by hand, right? Like what about
this psuedo code:

select case filesize
case >= 1,000,000,000,0 00
(display) filesize \ 1,000,000,000,0 00 & " TB?"
case >= 1,000,000,000
(display) filesize \ 1,000,000,000 & " GB"
case >= 1,000,000
(display) filesize \ 1,000,000 & " MB"
case >= 1,000
(display) filesize \ 1,000 & " KB"
case else
(display) filesize & " bytes"
end select

"Arjen" <bo*****@hotmai l.com> wrote in message
news:bh******** **@news2.tilbu1 .nb.home.nl...
Hello,

When I have read a file with x.xxx.xxx.xxx bytes it is sometimes handy to
show it in an diverent format than bytes.

Is there a handy way to do this?
Or is there a function for it?

When it is a big file I want to see a MB size and when it is a lower file
size then I want to see a kB size for example.

Thanks!

Nov 17 '05 #2
Actually Windows API provides such a function,
StrFormatByteSi zeA/StrFormatByteSi zeW. If you really wanted to you could use
that (through a COM object?).

Jerry

"Michal A. Valasek" <ne**@altaircom .net> wrote in message
news:OJ******** ******@TK2MSFTN GP09.phx.gbl...
Hello,

| It shouldn't be too much trouble to do it by hand, right? Like what about | this psuedo code:

there is no specific function to do that. Go the way "eruess" provided, but keep in mind, that kB, MB etc. is binary, not decimal, and use
multiplications of 1024, not 1000.

--
Michal A. Valasek, Altair Communications, http://www.altaircom.net
Please do not reply to this e-mail, for contact see http://www.rider.cz

Nov 17 '05 #3
Actually Windows API provides such a function,
StrFormatByteSi zeA/StrFormatByteSi zeW. If you really wanted to you could use
that (through a COM object?).

Jerry

"Michal A. Valasek" <ne**@altaircom .net> wrote in message
news:OJ******** ******@TK2MSFTN GP09.phx.gbl...
Hello,

| It shouldn't be too much trouble to do it by hand, right? Like what about | this psuedo code:

there is no specific function to do that. Go the way "eruess" provided, but keep in mind, that kB, MB etc. is binary, not decimal, and use
multiplications of 1024, not 1000.

--
Michal A. Valasek, Altair Communications, http://www.altaircom.net
Please do not reply to this e-mail, for contact see http://www.rider.cz

Nov 17 '05 #4

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

Similar topics

0
2250
by: Phil Powell | last post by:
// PROCESS XML CONTENT INTO DYNAMICALLY-NAMED ARRAYS foreach (array('mime', 'state', 'country') as $val) { $parser = xml_parser_create(); xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1); xml_parse_into_struct($parser, ${$val . 'XML'}, ${$val . 'XMLArray'}, $tags); xml_parser_free($parser); $myXMLArray = ${$val . 'XMLArray'}; for ($i = 1; $i < @sizeof($myXMLArray) - 1; $i++) { if ($myXMLArray) {
2
11693
by: IWP506 | last post by:
I just CANNOT figure out what is wrong with this! ------ $op1f = fopen("./test.txt","r"); $op1 = fread($op1f, filesize($op1f)); ------
4
5460
by: Ken | last post by:
I would like to measure the fileSize of the image (without uploading it - php). I use: var size_pic = document.getElementById('num1').childNodes.fileSize; alert("size = " + size_pic); which works on IE with one exception. With a first time displayed image, the script displays a size= -1 The image is displayed on the first pass. The fileSize script is located after the
2
2936
by: Pat | last post by:
Here is my problem that I am having with a current project. I went and backed up all my hard drives to DVD's. After backing up the drives, I used a batch file to get all the file names from the disk to a text file for future reference. I now have over 60 huge text files and would like to place the information into either a database or an excel document. I would like to read in from a text file and output the text file to an excel .cvs...
6
2796
by: coriolis_wong | last post by:
Hi, I need to transfer csv format file to DBase III format file. How do i do it in Python language? Any help is appreciated. Thanks.
14
2378
by: Manish | last post by:
The project I am developing doesn't involves database. I want to parse the mailbox file (.mbx) and store the summary in the text file for fast retrieval and display of information in the Inbox page. The sugegsted format are as: #1 ID : Subject : To Address: From Address...etc...
6
10190
by: thi | last post by:
Hi, Just wondering whether there is any filesize format function in c#? The reason i ask because i want to display the file size just like windows e.g. 100 KB, 1MB, 1GB etc... I am kind of hoping there is a method already built in c# as currently i have to write a custom one and it looks like this: private string formatsizekb(double dsize)
15
2037
by: Martin Maney | last post by:
To quote from zipfile.py (2.4 library): # Search the last END_BLOCK bytes of the file for the record signature. # The comment is appended to the ZIP file and has a 16 bit length. # So the comment may be up to 64K long. We limit the search for the # signature to a few Kbytes at the end of the file for efficiency. # also, the signature must not appear in the comment. END_BLOCK = min(filesize, 1024 * 4) So the author knows that there's...
5
2348
by: kirk | last post by:
I guess the easiest way to describe what I need for output is to give some examples. The biggest rule is the number cannot be larger than 3 digits after the formatting. --examples-- before: 30, after: 30 before: 300, after: 300 before: 3000, after: 3K before: 30000, after: 30K before: 30500, after: 30.5K // K meaning Kilo
0
8316
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8833
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8737
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8509
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8610
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7345
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5636
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
1967
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1730
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.