Lesson 0.7

File extensions and what they mean

Artifact: Reading any file's extension, predicting which program opens it, and turning extensions on

1. The promise

You'll be able to read a file's extension, predict which program will open it, and know that extensions are conventions — not contracts. You'll have file extensions turned on for the rest of your career.

2. The mental model

The extension is a sign on the front of the box that tells the OS which program to call when somebody double-clicks it.

The OS looks up the sign in its registry of file associations and calls the matching program. Change the sign and the OS calls a different program — even though the contents of the box never changed.

The vocabulary, said properly:

  • An extension is everything after the last dot in the filename. notes.txt -> .txt. holiday.photo.jpg -> .jpg. The rule is the last dot.
  • The default application is the program the OS calls when you double-click a file of a given extension.
  • A file association is the mapping in the OS from extension to default application.

3. You do it, with me

Step 1. Turn extensions on. macOS and Windows both hide extensions by default. For a developer, this is unworkable.

On macOS: open Finder. From the menu bar, choose Finder -> Settings -> Advanced. Tick "Show all filename extensions".

(SCREENSHOT: macOS Finder Settings -> Advanced — full window — "Show all filename extensions" checkbox highlighted)

On Windows: open File Explorer. From the menu bar, click View -> Show -> File name extensions.

(SCREENSHOT: Windows File Explorer View ribbon -> Show submenu — full window — "File name extensions" checked, highlighted)

Look at your Documents folder. Filenames now end in .docx, .pdf, .txt, .jpg — the truth was hidden from you until now.

(SCREENSHOT: a folder with both extension-on and extension-off filenames visible side-by-side — Finder or Explorer — full window)

Step 2. Read this cheat sheet. Twenty extensions every developer recognises on sight:

  • Text: .txt, .md (Markdown).
  • Web and config: .html, .css, .js, .ts, .json, .xml, .yaml.
  • Images: .jpg, .png, .gif, .webp, .svg.
  • Media: .mp3, .mp4, .mov.
  • Document: .pdf.
  • Archives: .zip, .tar.gz.
  • Installers and apps: .exe, .dmg, .msi, .app.

You don't need to memorise these. You need to recognise them when you see them.

Step 3. Change the default program for an extension.

  • macOS: right-click any .txt file -> Get Info. Expand the Open With section. Pick VSCode from the dropdown. Click Change All... to apply this to every .txt file from now on.

(SCREENSHOT: macOS Get Info window for a .txt file — Open With section expanded — Change All button highlighted)

  • Windows: right-click any .txt file -> Open with -> Choose another app. Pick VSCode. Tick "Always use this app to open .txt files".

(SCREENSHOT: Windows "Open with" picker — full window — "Always use this app" checkbox highlighted)

From now on, every .txt file on your machine opens in VSCode when you double-click it.

Step 4. Watch a lie. Make a copy of hello.txt and rename the copy to hello.jpg. Double-click it.

What happens depends on your OS, but it'll be one of: the image viewer opens and shows a "broken image" icon, or the OS asks what to do because the file doesn't look like a real image.

The bytes inside the file are still the letters h e l l o. Renaming changed the sign on the box. It didn't change the contents.

4. What you should be seeing

Every file in your Finder or Explorer windows now shows its extension. You can rename a file and the extension stays visible. You can predict the default program from the extension alone for at least ten of the cheat-sheet entries.

You also have one demonstration that extensions can lie — a .jpg file that's actually text inside.

5. Common stumbles

  • The dot mid-filename confuses you. holiday.photo.jpg has extension .jpg. Not .photo.jpg. Not .holiday.photo.jpg. The rule is the last dot.
  • You think renaming converts the file. It doesn't. Renaming notes.txt to notes.docx does not turn it into a Word document. Word opens it, sees the bytes aren't a real .docx structure, and complains. To actually convert, open the file in the source program and use Save As (or Export) to the new format.
  • Wrong default program on Windows. You double-clicked, picked the wrong program in the "Open with" dialog, ticked "Always use", and now every file of that type opens in the wrong place. Fix: Settings -> Apps -> Default apps -> Choose defaults by file type and pick the right one.
  • macOS hides .app on Applications. Visual Studio Code.app shows in Finder as just "Visual Studio Code", even with extensions turned on. That one is special-cased. Don't go looking for the .app extension — Finder is making a one-off exception.

6. You should know

8/16
Next