Contacts

Exact file size. Sizes of files and folders or what are KB, MB, GB. Basic units of information storage

In this article, I wanted to introduce my readers to the concept file/folder size, or even a program (considering that a program is a set of folders and files).

Any file or folder with files takes up local disks a certain amount of memory. That is, all files and folders have volume, in other words, weight or size.

Since school, we have known concepts such as grams and kilograms, meters and kilometers. The computer world also has its own units of measurement. They measure files and folders. Based on the “slang” of advanced users, we will determine how much a particular file or folder “weighs”. The main units of measurement are: bytes, kilobytes, megabytes, gigabytes, and terabytes.

1 KB = 1024 bytes

1 MB = 1024 KB

1 GB = 1024 MB

Let's decipher:

There are 1024 bytes in one KB (kilobyte).
One MB (megabyte) contains 1024 KB (kilobytes).
One GB (gigabyte) contains 1024 MB (megabytes).

How to find out file or folder size?

To find out the size of a file or folder with files, hover over the file or folder with the cursor and hold for a few seconds. A small window will appear with characteristics of the file or folder; one of the parameters is size.

If nothing appears when you hover over a file or folder, then right-click on that file or folder. From the opened context menu select "Properties".

A window will open indicating the size of this file or folder.

Why do we need to know the sizes?! For example, in order to determine whether we can write a file or folder to a disk (floppy disk, flash drive) or how much space is left on local disks.

In order for us to be able to determine this, we need to know how much information fits on a disk (floppy disk, flash drive):

  • Floppy disk - 1.44 MB (suitable for writing text files)
  • CD disk - 700 MB (suitable for recording music, small videos and programs)
  • DVD disc— from 4 GB (suitable for recording anything). The standard capacity of a DVD disc is 4.7 GB. There are also double-sided DVDs. This means that the recording can be on both sides - one and the other. These drives have a capacity of 9.4 GB. Dual-layer discs also exist, but they are less common. These disks have the following volumes: 1-sided 2-layer - 8.5 GB; 2-sided 2-layer - 17.1 GB.
  • Flash drives - from 1GB (suitable for recording anything)

That's all I wanted to talk about in this article.

Standard POSIX has its own method to get the file size.
Include the sys/stat.h header to use the feature.

abstract

  • Get file statistics using stat(3) .
  • Get the st_size property.

Examples

Note. Size is limited to 4GB. If not Fat32 system Fat32 then use the 64-bit version!

#include #include int main(int argc, char** argv) ( struct stat info; stat(argv, &info); // "st" is an acronym of "stat" printf("%s: size=%ld\n", argv , info.st_size) #include #include int main(int argc, char** argv) ( struct stat64 info; stat64(argv, &info); // "st" is an acronym of "stat" printf("%s: size=%ld\n", argv , info.st_size);

ANSI C (standard)

ANSI C does not provide a direct way to determine the length of a file.
We will have to use our minds. We will now use the search approach!

abstract

  • Find the file to the end using fseek(3) .
  • Get the current position using ftell(3) .

example

#include int main(int argc, char** argv) ( FILE* fp = fopen(argv); int f_size; fseek(fp, 0, SEEK_END); f_size = ftell(fp); rewind(fp); // to back to start again printf("%s: size=%ld", (unsigned long)f_size )

If the stdin file or pipe. POSIX, ANSI C will not work.
Will return 0 if the file is a pipe or standard stdin.

Opinion: You should use standard instead POSIX. Because it has 64 bit support.

If we talk about information in general, it is measured in BYTES. Measurement in these units began back in 1956. Then this value was quite enough. To make it clearer what value we are talking about, I will tell you that 1 byte = 1 character. With the development of technology, the volume of information has also increased, and measuring a large amount of information in BYTES has become inconvenient. Then the prefixes KILO-BYTE (KB), MEGA-BYTE (MB), GIGA-BYTE (GB), TERA-BYTE (TB), etc. appeared.

To understand how large or small these values ​​are, I will give the following comparison:
- 1KB (one kilobyte) = 1024 bytes, and this is the amount of information approximately equal to one printed sheet of A4 format;

— 1MB (one megabyte) = 1024 kilobytes, and this is the amount of information already in a decent volume of 600-700 pages!

— 1GB (one gigabyte) = 1024 megabytes, and this is already a whole library of 1024 books of 600 pages each!

— 1TB (one terabyte) = 1024 gigabytes, this amount of information is comparable to the average European library, which contains about 8 million books. For example, the Russian State Library contains about 43 million items.

Now let’s compare the volume and type of information regarding the media on which this information can be recorded.

— Floppy disk with a capacity of 1.44 MB. Once upon a time, the floppy disk was the main accessible medium of digital information, because... You could really record a lot of things on it. Nowadays, floppy disks are mainly used by accountants for storage. electronic keys and signatures. The reason is trivial - there is not enough space on a floppy disk to store modern information. You can record one or two photographs taken on a floppy disk. mobile phone with a 3 megapixel camera; five, ten Word, Excel documents.

— Flash drive with a capacity of 1GB. The most convenient information carrier at the moment. I took the capacity of the flash drive to 1GB to multiply the count, but in general, at the time of writing, there are also 64GB flash drives!
What can be recorded on a 1GB flash drive: one movie, of relatively good quality; about 200 music files in .mp3 format; about 200 photos good quality; many documents and small programs.

— CD disk with a capacity of 700MB. You can burn onto a CD: one movie in .avi format, in relatively good quality; about 150 music files in .mp3 format; about 150 good quality photographs; many documents and small programs.

— DVD disk with a capacity of 4.7 GB. You can burn onto a DVD disc: one movie in DVD or HDTV format; 4-5 films in .avi format of good quality; about 1200 music files in .mp3 format; about 1000 good quality photographs; sooooo many documents and programs.

— Hard drive with a capacity of 120GB. Here, in order not to write about the documents, I’ll compare it with the number of films that can be recorded on such a hard drive. So, on a 120 GB hard drive you can record 25 movies in DVD or HDTV quality!

Now let's figure out one by one how to determine the size of a disk, file or folder.
In Windows, you can determine the size of a file, folder, or disk in Explorer. You can launch “Explorer” by double-clicking with the LEFT mouse button on the “My Computer” shortcut on the desktop or using the “Win ​​+ E” key combination.

If you, for example, want to find out how much free space is left on a disk, in particular on a flash drive, then RIGHT-click on the image of the removable disk, usually it is labeled as “ Removable drive(F:)" or "Flash drive name (F:)", as in the picture:

So, right-click on the image of the removable disk - flash drive and select the “Properties” item in the menu that opens, at the very bottom. After this a window opens:


Here you can see how much is occupied (highlighted in blue), how much is free (highlighted in pink) and how much space is on the disk.

Thus, you can find out the remaining free space not only on a flash drive, but also on any removable or logical drive Winchester.

The scheme for determining the size of a file or folder is the same as with a disk. Those. find it on disk required file or folder, click on it (s) with the RIGHT mouse button and look at “Properties”.


All the necessary information will be there.


If you want to find out the size of a group of files or folders, then you need to select them and do the same operations, i.e. RIGHT-click on one of the selected files or folders, select “Properties” and view the size.

Yes, the second part of the lesson does not quite fall under the “Computer Basics” heading, but nevertheless. If you have any questions, you can always ask them in the comments.

Did you like the article? Share it