Computers and modern gadgets

First of all, let's say that we will talk here about the FAT and NTFS file systems, as the most common ones, and nothing will be said about the file systems used in non-Windows systems, since such systems are beyond the scope of the author's interests. And now - to the point.

It would seem that there can be some ambiguity when talking about file size. How much data is written into it is the size (or length). How many bytes it has from start to finish (and this number is recorded in the file system as the file size), that's the size, right? As Shelmenko the batman said, that’s how it is, but it’s just a little bit different.

Do an experiment. Take any executable file and copy it with the command
copy something.exe something else.exe

If you've encountered this before, you already know that the resulting file will be much shorter than the original one and will not be a copy. The reason is simple: the copy program, launched without the /b parameter, copies the file until it encounters a byte with code 27h, this character is called the “end of file”.

So, we already have two different signs of the end of the file - by the number written in the file system, and by a special byte in the body of the file. However, it is worth noting that the second sign remains from the times when files were predominantly text and is now practically not used.

In file systems that use clusters, and FAT and NTFS refer specifically to such file systems, there is a third size - the size of the file on the disk, that is, the total size of the clusters allocated to this file. In FAT file systems, this size is greater than or equal to the size of the actual file. The difference between the sizes, if there is one, is the so-called tail of the file - this is wasted space on the disk, the cost of placing files in clusters, and not end-to-end one after another, although file systems with such file placement also exist.

However, sometimes this place is used. In particular, in the days of floppy disks, there were programs that allowed you to write data to the tails of files in order to covertly transfer information on such diskettes. After all, it is impossible to access the tails of files using standard means.

If we include NTFS in consideration, the picture will be complemented with new touches.
First of all, the size of the file on disk may be smaller than the actual size of the file.
If the body of a file fits into the free area of ​​an MFT file record, then the file does not occupy any clusters on the disk.

The maximum size of such a file depends on the size of the record and is approximately 600 bytes for a small record (1 KB) and 3600 for a large record (4 KB). However, it should be noted that until recently, Windows showed the size of such a file on disk as equal to one cluster, although in fact no cluster was allocated to the file.

If the file is compressed, then its size on disk can be noticeably smaller than the actual length of the file (the amount of data in it).

Further complicating the picture are so-called sparse files. They contain useful data only in certain sections of the file, and the rest of the file is not used at all. Take as an example the changelog file \$Extend\$UsnJrnl found on almost every computer (don't try to see it in Explorer or other file managers, it won't work).


It can be several gigabytes long, but it usually contains only 32 megabytes of meaningful data at the very end. And the rest of the data does not contain any data at all, it does not take up disk space, and when you try to read data from this part, the system will issue a set of zeros without even accessing the disk.
If the reader wishes to experiment with sparse files, such a file can be created using the fsutil sparse command. And in your spare time, you can think about what the real length of the file is, if the system wrote the number 4 GB in the corresponding column, but the actual data in the file is only 32 MB and it also takes up 32 MB on the disk.

And finally, let's talk about one more length: the length of valid data. This length and the functions that set it are of interest almost exclusively to programmers, but ordinary users may occasionally encounter it.

In FAT file systems, this concept does not exist, and functions that use this value write zeros in the appropriate places in the file body. In NTFS, this length is a file characteristic.

Let's try to explain what we are talking about using an example. Take a flash drive (a flash drive is used for clarity, since it is slower than a hard drive when handling large amounts of data) of a gigabyte in size, formatted in FAT32, and create a large file on it with the command
fsutil file createnew k:\trial.txt 900000000

If the letter assigned to the flash drive is different from K, then correct the command accordingly.
You will find that the file creation procedure will take quite a long time, half a minute or more (although the “file created” message will appear immediately, you will have to wait for the command line prompt to appear). This is not at all surprising, because the description of the () command says that the file being created consists of zeros. And our file turned out to be 858 megabytes, so writing it should take quite a bit of time.

Now format the flash drive to NTFS, for the purity of the experiment it is better to take the same one, and repeat creating the file. This time the operation will take place almost instantly. There is no longer any need to write zeros to the file body; it is enough to allocate space for the file and set the length of valid data for it to zero. The body of the file will contain “garbage” that was written in these sectors, but when reading data, this data will not be accessed - having discovered that the length of the valid data is zero, the system will not read anything further than this zero - after all, this data are invalid. They can be made valid by changing the value of the length of the valid data.

Let's look at this with an example. Create a new file on one of the scratch disks formatted in NTFS. Hundreds of megabytes are completely unnecessary; a dozen or two kilobytes will be quite enough:
fsutil file createnew C:\trial.txt 10000

Now open it using any file viewer like FAR.


As you can see, there are indeed zeros in the file. But if you look at this file using any disk editor that accesses sectors directly, for example dmde, the picture will be different.

If we open volume C as a logical device and look at the contents of the file, we will see the same zeros.


But if you open the disk as a physical device, then in the same sector (pay attention to the LBA numbers - the difference of 63 arose due to the fact that the beginning of the partition is shifted relative to the beginning of the disk) we will see data that was previously written to some later deleted file.


And if we increase the length of the valid data, we will see this data in the file. Let's set this length to 300 bytes:

fsutil file setvaliddata C:\trial.txt 300

Please note that the parameter in this command cannot be set arbitrarily, but must be no less than the current value of the valid data length and no more than the file size. You cannot reduce the length of valid data with this command.

Now look at the contents of the file again. Please note that we did not write any data into it!


It turned out purely by chance that this file contains quite a lot of meaningful text, which makes the picture more visual. 300 decimal bytes is 12c hexadecimal, and it is at this byte that the text breaks off and the zeros begin. If you move the boundary of the actual data even further, then the following lines will “appear.”

Let's sum it up

There are two physical file lengths - the size of the file recorded in the file system and the space occupied on disk. There are also two logical file lengths - the end-of-file sign (EOF byte - 27h) and the length of the actual data. Empty regions in sparse files can also be considered as part of the logical length - think of \$Extend\$UsnJrnl, where a large array of missing data ends with thirty-two megabytes of real data.

So, usually when we talk about the length of a file, we mean the number stored in the file system. But, as you can see, options are possible!

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 a certain amount of memory on local disks. 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 the cursor over the file or folder 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 context menu that opens, 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 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.

I propose to consider what kind of animals these are - JPG and RAW photo formats, what they affect and when you should pay attention to them. What is photo size and file weight, how are they measured and what do they depend on.

Almost all photo cameras can save photos in JPG format (even phone and tablet cameras). In all SLR and non-SLR cameras, as well as in advanced compacts, in addition to JPG, there is at least RAW and RAW+, and sometimes TIFF.

To understand the formats, you first need to agree on what is meant by the concepts of “size” of a photograph and “weight” of a file (photo). I propose to consider these concepts on more tangible objects... for example, on goodies.

1 | What is a pixel:


The size of objects is measured in meters, the size of photographs is measured in pixels (px).

If you measure the size of this bowl of berries, it will be about 10 centimeters in height and about 13 centimeters in width... approximately. That is, we are used to measuring objects in centimeters (meters, kilometers, and so on). If we talk about the photo of the same vase, then the original size of the photo is 7360 pixels (px) wide by 4912 pixels (px) high. This is the maximum photo size that my Nikon camera is capable of. To post this photo on the website, the photo size was reduced to 1200px by 798px (I’ll tell you why a little later).

What is a pixel? Taken with digital cameras or digitized on a scanner, photographs are a combination of tiny colored squares - pixels. If you zoom in on any photo, you will see these pixels. The more such pixels in a photo, the more detailed the picture.


A photo fragment enlarged a thousand times - pixel squares are visible.

2 | Is it possible to convert pixels to centimeters:

This is exactly what happens when you need to print photos on paper. Here you will need one more indicator - the pixel density (resolution) that the printer (or other machine for printing photos) can print. The printing standard for photographs is 300 dpi (dots per inch). For example, for printing in beautiful glossy magazines, photos with a resolution of 300 dpi are used.

So that you don’t rack your brains over dividing the photo size by the resolution and converting inches into centimeters, any program for viewing and editing photos (for example, Photoshop) has a function for viewing the photo image size in centimeters. You will need it to understand the maximum size of a photo in good quality (with a resolution of 300 dpi) you can print on paper or other tangible media.

For example, this photo with tropical Frangispani flowers can be printed in size 61 cm by 32 cm.


Photo size in pixels and centimeters in Photoshop

To find out the photo size in pixels and centimeters in Photoshop, you need to press the key combination Alt+Ctrl+I or go to the Image menu Image size.

Let's return to the reality of digital photos - to pixels and photo sizes in pixels. What happens if you reduce the number of pixels in a photo? The answer is that the quality of the photo will deteriorate. For example, I took a photo of the same bowl of berries at the beginning of the article and reduced the size of the photo to 150 pixels wide. With this reduction, the program destroys some of the pixels. The photo has become miniature:

Now let’s try to “stretch” the photo across the entire page:


A stretched picture looks cloudy and fuzzy

As you can see, the detail is no longer the same, since some of the pixels (and with them the details) are missing.

Of course, if you use this reduced image as a small icon or a small image in a Power Point presentation, it will look quite normal, but it is clearly not suitable for printing in a half-page magazine.

3 | What photo size (how many pixels) is optimal:

If you plan to print photos someday, then save photos in the highest possible resolution, which your camera will only allow (carefully read the instructions for your camera to correctly adjust the photo size).

In some cases, you need to reduce the size of photos. As I wrote above, for the site I reduce the photo size to 1200 pixels on the long side. If you upload a photo in full size, the site pages will take a very long time to load, and many visitors may not like this (not to mention the Google and Yandex search engines).

Photo sizes are measured in pixels (px). The number of pixels determines the size of the photo on monitor screens, and what size the photo can be printed.

4 | File size or "photo weight":

Now let's look at the “weight of the photograph”. Historically, there has been a lot of confusion on this issue and the file size is quite often called the “weight of the photo,” which is more convenient than correct. File sizes are measured in megabytes (MB) or kilobytes (KB). And here it’s worth remembering that, unlike kilograms, where 1 kg = 1000g, 1 megabyte = 1024 kilobytes.

How this looks in practice: imagine the situation that your camera has a memory card that says 64GB (gigabytes). If you look at exactly how many bytes there are (right-click on “properties” on your computer), it turns out that there are 63567953920 bytes on this memory card and this is equal to 59.2 GB. How large the files your camera produces will determine how many photos will fit on that memory card. For example, I can fit 830 photo files in RAW format (read about formats below).

What determines the file size:

  • Firstly, on the size of the photo (what is measured in pixels): the file with the first photo of berries (photo size 7360x4912 px) is 5.2 MB, and it, reduced to 150 px, will “weigh” 75.7 KB (in 69 times less).
  • Secondly, on the format (JPG, TIFF, RAW), which you can read about below.
  • Thirdly, the file size (or “photo weight”) depends on the number of details: the more there are, the “heavier” the photo (which is most relevant for the JPG format).

Many details - more weight of the photo

For example, in this photograph with monkeys from Sri Lanka there are many small, clear (in the language of photographers, “sharp”) details and the file size of this photograph is 19.7MB, which is significantly larger than berries in a vase on a white background (5.2MB).

If you ask what size photo can I print from a photo that weighs 2MB. No one can answer you until they know the number of pixels. And it’s better, of course, to also look at the photo, since some craftsmen like to get a photo from the depths of the Internet, increase the number of pixels programmatically, and then want to print it on the cover of a magazine. It turns out as in the example above with a stretched photo of a vase 150 px wide.

File size (often called "photo weight") is measured in megabytes (MB) or kilobytes (KB) and depends on the format, pixel size, and detail of the photo.

5 | Photo formats:

And finally, we come to the issue of image formats and type of file compression, which also determine the size of the photo file.

Almost all photo cameras can save photos to JPG format(even cameras on phones and tablets). This is the most common image format and is “understood” by all computers and image viewing programs. In JPG format, photos can be uploaded to social networks, posted on a blog, added to Word, Power Point files, and so on. JPG can be processed in Photoshop, Lightroom and other image editing programs.

From my practice: if I want to take a photo for a social network and quickly upload it, then I either take a photo with my phone or set the file format to jpg in my camera.

Something to remember about the jpg format is that it is a compressed format and has compression levels. The higher the compression ratio, the smaller the file size due to the reduction in detail and quality of the photo. Therefore, it is not recommended to repeatedly edit and resave (re-compress) the same photos in jpg format.


When saving a file in jpg format, the compression level is selected (example from Photoshop).

In all SLR and non-SLR cameras, as well as in advanced compacts, in addition to JPG, there is at least RAW, and often also TIFF.

A little theory:

  • TIFF(English Tagged Image File Format) - a format for storing raster graphic images (including photographs). TIFF has become a popular format for storing images with high color depth. It is used in printing and is widely supported by graphics applications.
  • RAW(English raw - raw, unprocessed) - a digital photography format containing raw data obtained from a photo matrix (the thing that replaced film in digital cameras).

Personally, I never shoot in TIFF format. I can’t even think of why I need this if there is RAW. I can use TIFF without compression to save photos that I still plan to modify in Photoshop.

6 | Advantages and disadvantages of the RAW format:

My camera is almost always in RAW format, since I plan to process (edit) photos in Lightroom or Photoshop. RAW has a number of significant disadvantages:

  • There is no way to view files without first converting them. That is, to view photos in RAW format you need a special program that supports this image format.
  • Larger file size than when saving in JPEG (with my Nikon D800 camera, the file size with a photo in RAW format is 74-77 MB). This means that fewer photos will fit on the flash drive.
  • RAW cannot be uploaded to social networks, blogs, and sometimes even sent by mail. First, RAW needs to be converted to a RAW converter (for example, Adobe Camera Raw) that supports the file type from your camera model.

Why do professional photographers often prefer RAW over JPG? Because RAW:

Save this article as a keepsake on Pinterest
  • provides more options for image correction: white balance, contrast, saturation, brightness and noise level,
  • allow you to further correct images without the appearance of defects,
  • allows fine correction of lens imperfections (vignetting, chromatic aberration).

So, if you plan to carefully process your photos in Photoshop or Lightroom, sensitively feeling “artifacts” and halftones, “overexposures” and “dips” in the shadows, then shoot in RAW. Just remember that to get a good result, you will need to understand the settings and operation of RAW converters. Think about whether you need this headache? Maybe you should shoot in JPG and spend more time relaxing and not on the computer?

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. Now, floppy disks are mainly used by accountants to store 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 mobile phone with a 3 megapixel camera on a floppy disk; 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 good quality photographs; 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 “Removable disk (F:)” or “Name of flash drive (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 of a hard drive.

The scheme for determining the size of a file or folder is the same as with a disk. Those. Find the desired file or folder on the disk, click on it with the RIGHT mouse button and see “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.



Probably, you often see on sites a signature indicating the file size. This indicator is not signed by anyone. This issue is solved by writing a function in php. As a result, it will output a line like:

File size: 2.3 MB
It is very convenient when downloading any materials from the site. So let's get started.

Create a PHP function that determines the file size

The function will be quite simple and straightforward. Uses three built-in functions:

file_exists- checking for the presence of the specified file or directory.

filesize- determine the file size. Returns the result in bytes. If the file is larger than 2 GB, then, depending on the server, it may display incorrect results.

round- a built-in function that shortens the output value to an integer and one tenth after the period separator.
The function checks for the presence of the file itself, then sequentially tries to determine how large the file size is - if it is more than 1024 bytes, then the result should be output in MB, if it is more than 1024 MB, then it should be output in GB. And at the end of each step, the built-in round function rounds the result from many digits to a whole value and one tenth with a separator.

Now let's create a function file. It is customary to keep such files in a separate folder. For example function.

PHP code(file function.php)

// function arguments will be the path to the file
function get_filesize($file)
{
// go to file
if(!file_exists($file)) return "File not found";
// now determine the file size in several steps
$filesize = filesize($file);
// If the size is greater than 1 KB
if($filesize > 1024)
{

// If the file size is more than Kilobyte
// it's better to display it in Megabytes. Converting to MB
if($filesize > 1024)
{
$filesize = ($filesize/1024);
// And if the file is more than 1 Megabyte, then we check
// Is it larger than 1 Gigabyte
if($filesize > 1024)
{
$filesize = ($filesize/1024);

return $filesize." GB";
}
else
{
$filesize = round($filesize, 1);
return $filesize." MB";
}
}
else
{
$filesize = round($filesize, 1);
return $filesize." Kb";
}
}
else
{
$filesize = round($filesize, 1);
return $filesize." byte";
}
}
?>
We created the function. All that remains is to apply it.

PHP code

include_once "function/function.php"; // include the file with the function

// insert a path or a variable with a path for processing by the function
$size = get_filesize("images/photo.jpg");
echo "File size: ".$size.""; // output the result with size
?>
All is ready! Enjoy it for your health!
Thank you for your attention! And good luck with your work!

If you notice an error, select a piece of text and press Ctrl+Enter
SHARE:
Computers and modern gadgets