How Zipped Folders Work

Share
In this article, we'll learn a bit about how zipped folders work, which are files that look like folders, but aren't actually folders.

How Are Zipped Folders Different From Normal Folders?

What's the difference between a normal folder and a zipped folder? What makes them "zipped"?

In essence, files and folders are concepts of a filesystem. Filesystems come in various formats, such as NTFS, FAT, Ext4, and so on. You may have heard about "formatting" your computer. What that actually means is creating a partition in a mass storage device in your PC, then installing a filesystem format in it. Filesystems are the thing that keeps track of files and folders in a mass storage device. Without a filesystem, you don't have files, so you can't even install an operating system like Windows in your PC without formatting it first.

In any such filesystem, a zipped "folder" would be considered a file, not a folder. It's just a normal file as far as the filesystem is concerned.

In a normal folder, the filesystem keeps track of what files are contained inside the folder. In a zipped folder, the filesystem has no idea what files are contained inside the zipped folder. A zipped folder may contain files and folders with in it, but it's the zipped folder itself that keeps track of them. It's like the zipped folder is a "filesystem inside a file" inside the real filesystem.

Just like there are various formats of filesystems, there are also various formats of zipped folders, also called "archives," which keep track of their contained files in different ways.

The simplest zipped folder you see on Windows is a file with a .zip file extension. A .rar extension is used by WinRAR archives. A .7z extension is used by 7zip archives. On Linux, it's common to see .tar.gz, which is a tarball archive compressed by a program called gzip.

There are some technical differences between these that we'll see below.

It's worth noting that some types of files also work like zipped folders but aren't referred to as such. For example, an ISO image is type of file that contains files and folders inside of it for burning them in a CD, but we don't call them zipped folders.

Why Are Zipped Folders Necessary?

Why do we need zipped folders if normal folders already exist? There are two main reasons: because a zipped folder is a file, and because of compression.

Files as a Single File

In some cases, we may have a software that only works with files, and not with folders, so putting a lot of files inside one file is a way to get around this limitation.

For example, let's say you have 500 photos that you want to send someone. You could send them by e-mail, or upload them to some website that lets other people download the files you uploaded. However, because it's 500 photos, 500 different files, the person would have to download each single file separately.

If you package them inside a single zipped folder, then all 500 files become one single file. Then you send it to someone else, they "unzip" the zipped folder, and extract all the 500 files from inside the zipped folder to inside the real filesystem.

Note: it's perfectly possible for software to handle folders like zipped folders, but that would be unnecessarily complicated. After all, if you wanted to send a bunch of files as a single package, you could just use a zipped folder.

Compression

Compression means that putting 500 photos inside a single zipped folder will make it occupy less space. The file size of the zipped folder will be smaller than the sum of the file sizes of all files contained inside of it. This always happens, by the way.

Filesystems split a mass storage device's partition in "blocks" that can be used to store files. For example, if the block size is 4 kilobytes, then a file that is only 1 kilobyte will occupy 4 kilobytes, because the whole block will be reserved to store the file. A file that is 5 kilobytes will occupy 8 kilobytes, and so on. On Windows this is displayed as "Size on disk" in a file's properties. A zipped folder could more tightly pack the files to avoid wasted space.

On top of that, some zipped folders may have a compression algorithm applied to the files' data. Compression algorithms can greatly reduce the total size of the files in some cases, which can help you save storage space for long term storage. For example, let's say you have lots of photos from many years ago that you want to store. If they are important, you should have multiple backup copies in case you lose one of them, but because it's a lot of data, that can be expensive for you. You could save time and money by using a compressed format before storing them.

In the past, compression was specially important because Internet speeds were very slow, so it would take a lot of time to download, and also to upload, zipped folders if they were too large. One reason why WinRAR was so popular, for example, was because of its compression features.

Lack of Filepaths

Applications don't have direct access to the data contained inside a file in your computer. Every time they need to open (or load) a file, or create a file, or save a file, they send a request to the operating system which handles loading and saving of the data. This request contains the filepath of the file to be loaded, created, or saved. Every file in a filesystem that the operating system can access has a unique filepath.

The files inside a zipped folder don't really have a filepath, since for the filesystem the zipped folder is a file, not a folder.

This means that you can have filepath like C:\photos\cat.jpg, with cat.jpg is a file inside the folder photos, but you can't have a filepath like C:\photos.zip\cat.jpg, with cat.jpg inside a zipped folder photos.zip.

Since such filepaths aren't supported by the operating system, it's simply not possible for an application to open a file that is contained inside a zipped folder. You must get the file out of the zipped folder first, into the real filesystem, so it can have a valid filepath, so the application can make a valid request to the operating system.

Note: it's technically not impossible for the operating system to handle filepaths to files inside zipped folders like this, but in practice operating systems don't do this, since it would just overcomplicate everything. It's much simpler to just extract the file first instead.

Extracting and Opening Files inside a Zipped Folder

In order to use a file inside a zipped folder it's necessary to extract it to your real filesystem.

In the past, this was more obvious because native support for zipped folders was terrible. Nowadays, operating systems are smarter, which means the process is more confusing for beginners.

For example, on Windows 11, you can double click on a zipped folder in the file manager, and it will just open the zipped folder as if it were a normal folder. On Windows XP, this wouldn't happen, so it would be clearer that it's not a normal folder.

There are still some formats, like tarballs, that may require special software to explore on Windows, such as WinRAR and 7zip. These software look very similar to a file manager, and you can drag and drop files from their main pane into a normal folder to extract them. They try to make it look like you're working with files in a normal folder as much as possible, but keep in mind that you are not.

For example, you can often double click on a file inside a zipped folder to open it. However, the way this works is different from how you open a normal file.

When you double click on a normal file, the file manager tells the operating system to open the application associated with the file type of the file, and tells that application to open the file indicated by its filepath.

But a file inside a zipped folder doesn't have a filepath, so what happens we double click on it?

The program displaying the files will first extract the file to temporary folder, then give the filepath of the extracted file to the application. This can have a few unexpected consequences depending on how the software involved were programmed.

Saved files are not saved: it's possible that if you open a file from the zipped folder, edit it, and save it, it won't be saved inside the zipped folder. That's because the file you are editing is actually a temporary file that was created to store the data of the extracted file, so when you save the file, you saved the temporary file in the real filesystem, not the file inside the zipped folder. It's possible that the program displaying the zipped folder is smart enough to detect the temporary file was overwritten and automatically place the updated file inside the zipped folder, however, this may not necessarily be the case. For example, if you open a zipped folder, double click on a file to edit it, then close the zipped folder, then save the file, it's possible that the program that is watching the temporary file for changes was terminated when you closed the zipped folder, so changes to the temporary file won't be reflected inside the zipped folder.

Automatically saved backups don't work: some applications may create an automatic backup file next to the file you opened so you can recover it in case the application crashes. For example, Krita does this. Since the file is saved in the same folder as the opened file, it may not work with extracted files if each time you double click on the file the zipped folder browser extracts it to a different temporary folder.

Opened files are corrupted: when you double click on a file inside a zipped folder, the program displaying the zipped folder might extract ONLY the file you double clicked to open, meaning that the other files in the zipped folder won't be extracted. If the application that opens the file requires sibling files to work, it will be as if the file is corrupted, since it's missing data. For example, if you have an executable file (.exe), sometimes these files needs a .dll file that must be presented in the same folder. But if you double click the .exe inside the zipped folder, only the .exe is going to be extracted, not the .dll, and then you'll get an error that says a .dll is missing because it wasn't extracted together with the .exe. This can happen if you downloaded the portable version of an application, for example, which typically comes inside a .zip file.

Opening files may take a long time: in a simple, uncompressed zipped folder, opening a single file requires only copying its data from inside the zipped folder's file to the real filesystem, which only depends on the size of the file you're extracting. The bigger the file, the long it will take to copy. In a compressed zipped folder, the files are smaller, but it takes longer to extract them since the uncompression algorithm must be executed. On top of that, the compression algorithm may have compressed all files as a single compressed object instead of compressing each file separately. This means that in order to uncompress a single file inside the zipped folder, the algorithm must uncompress ALL FILES inside the zipped folder. In other words, when you double click on a single file, it will feel like the program is extracting all the files to a temporary folder and then deleting everything except the file you clicked on.

With these issues in consideration, it's often easier to just extract all files before doing anything with them.

Written by Noel Santos.

About the Author

I'm a self-taught Brazilian programmer graduated in IT from a FATEC. In a world of increasingly complex and essential computers, I decided to use my technical expertise in hardware, desktop applications, and web technologies to create an informative resource to make PC's easier to understand.

View Comments