Subdirectory

Updated: 12/10/2023 by Computer Hope
Illustration of a directory with several subdirectories.

In a computer file system, a subdirectory is a directory contained in another directory, called a parent directory. A parent directory may have multiple subdirectories.

In operating systems with a GUI (graphical user interface), such as Microsoft Windows, a directory is called a folder, and a subdirectory is called a subfolder.

Note

A subdirectory may also be called a child directory since it's a directory of a parent directory.

Subdirectory examples

Every directory except the top-level root directory is a subdirectory of at least one directory. The list of parent directories of a directory or file is called its path.

In Windows

The following is an example of a file's path in Microsoft Windows, including its parent directories.

Windows command line path

In Linux

In the following example path in a Linux operating system, public_html is a subdirectory of computerhope, a subdirectory of c, etc. The root (/) is the only directory that is not a subdirectory because it has no parent directory.

/home/users/c/computerhope/public_html/

Subfolder examples

Like a subdirectory, a subfolder is any folder that is a child of another folder. In the example below, Fonts and System32 are subfolders of the Windows folder.

-Windows Folder Windows
+--System32 Folder System32
+--Fonts Folder Fonts

How do I create a subdirectory or subfolder?

You can create a subfolder from Microsoft Windows or another GUI by opening the folder containing the subfolder and creating a new folder. For example, if you have a folder called "Games" and want to create a subfolder named "Doom," move into the Games folder and create a new folder called "Doom."

To create a subdirectory from a command line, change to the directory that will be holding the subdirectory and create a new directory. Alternatively, you could create a subdirectory in another directory using the full path. For example, using the Windows command line mkdir command, you could create the subdirectory "doom" in the "games" directory by typing "mkdir games\doom" at the command line.

How do I get a list of subdirectories?

From a command line, you can see all subdirectories with the dir command (in Windows) or the ls command (in Linux).

For example, in the Windows command prompt, type "dir" and any <DIR> is a subdirectory of the current directory. If you only want to view subdirectories and not files you can type "dir /ad" a switch to only display all directories. To see all subdirectories and subdirectories of those subdirectories, type "dir /ad /s" at the prompt.

Tip

To get a more pleasing view of all directories and subdirectories, use the tree command.

Operating system terms, Parent, Recurse subdirectories