473,890 Members | 2,048 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 3395
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
2273
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
11704
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
5470
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
2949
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
2808
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
2398
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
10200
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
2057
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
2356
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
9972
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9812
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
10795
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
10898
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
9612
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...
1
8001
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7154
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();...
0
6032
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3261
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.