File extensions are awesome

The file extension (like .docx or .txt) tells your computer what to do with a file. See what those few letters do.

Ryan Schuetzler
Computers Are Awesome
5 min readApr 16, 2020

--

Originally published at https://www.computersareawesome.com/file-extensions-are-awesome/

Photo by Maksym Kaharlytskyi on Unsplash

What you’ll learn

  • What file extensions are
  • How to change a file extension
  • How to choose what program Windows uses to open a certain file type

Just about everything your computer does or can do is because of files stored on the computer. You’ve probably worked with a bunch of different kinds of files: JPEGs for pictures, MP3s for music, or DOCX files for documents, for example. There are probably thousands of other files you’ve interacted with without knowing. Every time you run a program/app on your computer, you’re running “executable” code, which is just another way of saying it’s a file (or a bunch of files) that has instructions to tell your computer what to do.

Example of files on Windows

Show file extensions

Every file has “file extension” that tells the computer what kind of file it is. For example, in our screenshot here, we have an MP4 video file, a PDF document, and a JPEG image. By default, Windows hides file extensions from you, and only shows the type of file in the “Type” column. I highly recommend changing that so you always know what type of files you’re working with. Just click on “View” in the file explorer and check the box to show file extensions.

Changing file extensions

Now that you can see the file extensions, you can change the file extension. Most of the time, all this does is confuse your computer so it doesn’t know how to open the file.

  1. Open your File Explorer (hit the Windows key on your keyboard and type “File Explorer”), then open the Desktop by double-clicking it.
  2. Create a new text file (Right-click > New > Text Document) and name it test.txt
  3. Double-click the new file to open it in Notepad (a text editor) and type (or copy) the text below:
  1. Double-click on the file. Note that it just opens in the text editor
  2. Now click the file and hit the F2 key on the keyboard (up at the top of your keyboard). Use the arrow keys to move the cursor over to the txt extension part of the filename. Delete that, and type bat in its place (make sure you leave the . so the filename is test.bat.
  3. Read the warning that pops up. “If you change a file name extension, the file might become unusable.” You definitely want to change it, so click “Yes”.
  4. Now double-click the file again. Instead of opening in Notepad like it did before, it now opens in a program called the Command Prompt.
  5. Read your test message, then press any key to close the window.
A Windows command prompt window showing a test message
What you should see when you double-click the test.bat file

When you changed the file extension, it told the computer that this was a different type of file, even though the contents were exactly the same. For a .txt file, the default is to open Notepad. For a .bat file, the default is to open and run it in the Command Prompt.

Think of the file extension like a wrapper that tells your computer what the file is for. Changing the wrapper doesn’t change the contents, it just changes how you think about using it.

Different bags, same product

In this case, we were able to change the behavior of the file by change its extension. That doesn’t work very often. Most of the time when you change the extension, it just breaks and means that Windows doesn’t know what to do with the file anymore. That’s why it gave you that warning before changing the file to .bat. Remember that changing the file extension does not change the contents of the file. So if you take a picture with a .jpg format and change it to .mp4, it doesn't magically make it a movie. Like filling the mayonnaise in the whipped cream tub, changing the container doesn't change the contents.

You can also tell Windows that you want to open a file with a different program than the default. If you create a new text file called test2.txt (Go back to step 2 above if you need a reminder), you can double-click the file to open it in the default program, Notepad. If you wanted to use a different program to open it, you can right click and find the option that says "Open with". Mousing over this option will open another menu that shows a list of programs Windows knows about that can open the file. In my case, I have Notepad, Visual Studio Code, WordPad, and Adobe Illustrator that have all told Windows they can open .txt files.

The “Open with” menu for test2.txt

There’s surprisingly even more stuff we can get into with file extensions later. For now, it’s good enough to know what they are, how to see them, and how to change them.

Reflection questions & Experiments

  • What are the file extensions used for the files you usually work with?
  • What happens if you change the test.txt file to be test.jpg?
  • What happens if a file has multiple extensions (like test.txt.jpg or test.jpg.txt?)

--

--

Ryan Schuetzler
Computers Are Awesome

A professor of information systems who loves teaching people how to more effectively use their technological tools.