How to List Folders Using CMD and PowerShell Commands

In this tutorial, you will learn how to list files, folders, and subfolders using Windows CMD commands and PowerShell.

I’ll also demonstrate using the NTFS Permissions Tool, which is a graphical program that displays the permissions on folders and subfolders.

In this article

Check it out.

List Files and folders using the DIR Command

The dir command is built into all versions of Windows. It is an easy to use command to list files, folders, and subfolders from the Windows command prompt.

Let’s look at some examples.

Example 1. List files and folders in the current directory

To list the files and folders in the current directory, open the Windows command prompt, enter dir and press enter. The dir command by default does not display subfolders.

dir

In this example, my current location is c:\it, so when I run the dir command it will list everything in this folder.

cmd list folders

I have put the command output into colored boxes to explain what each column means.

  • Red = This column is the last modified date of the file or folder
  • Green = Indicates if the item is a folder, folders are labeled with DIR
  • Purple = The size of the file
  • Yellow = Name of the file or folder.

Example 2. List subfolders

Use the /s option to include subfolders.

dir /s

I ran the command from the c:\it location and it lists all subfolders and files from this directory. I’ve highlighted some of the subfolders in the screenshot below.

cmd list folder and subfolders

Example 3. Specify a directory path

To list files and folders from a specific directory enter the complete directory path.

dir /s c:\it

For example, if my current location is the root of c: and I type dir /s c:\it the command will display the items from the c:\it directory.

Example 4. Export list of files and folders

To export the screen output use the command below. You can name the file whatever you want, in this example, I named the file files2.txt

dir > files2.txt

The file will be saved to the current directory.

Pretty easy right?

I covered some of the most basic dir command options. To see a full list of options type dir /? and press enter.

To learn more about the dir command check out the Microsoft dir documentation page.

Display Folder Structure using TREE Command

The tree command is another built-in Windows command. This command will display the contents of a directory in a tree structure. This can be useful to give you an overview of the folder layout.

You must specify a path or this command will start at the root of c

Example 1. List all folders and subfolders using TREE

To list all folders and subfolders enter the tree command and the path.

tree c:\it\toolkit

Example 2. List all folders and files using TREE

To include files with the tree command use the /f option.

tree c:\it\toolkit /f

In my experience, I never use the tree command. I find it more useful when a command provides more details like modified dates, permissions, ownership, and so on. If you just need to see the files and folders with no other details then this is a great option.

Powershell List Folders and Subfolders

You can use the Get-Childitem PowerShell cmdlet to list files and folders. The Get-Childitem cmdlet is similar to dir but much more Powerful.

Let’s look at some examples

Example 1. List files and folders using Get-Childitem

This example gets the folder contents from a specific directory

Get-ChildItem -path c:\it\toolkit
powershell get list of folders

By default, the Get-ChildItem cmdlet lists the mode, LastWriteTime, Length, and Name of the filer or folder.

The mode can be the following:

  • l = Link
  • d – directory
  • a = archive
  • r = read-only
  • h = hidden
  • s = system

Example 2. Get subfolders using Get-ChildItem

Use the -Recurse option to get subfolders and files.

Get-ChildItem -path c:\it\toolkit -Recurse
powershell list files and folders

Example 3. Get items using the Depth parameter

You can use the -Depth parameter to control how many subfolders deep to include in the list.

Get-ChildItem -Path C:\it -Depth 2

Example 4. PowerShell List only specific file types

In this example, I will list only files that end in a .msi file extension. This will search all subfolders in the directory path.

get-childitem -path c:\it -include *.msi -recurse

Example 5. PowerShell List only folder or files name

The -Name parameter will only return the file or folder name.

Get-ChildItem -path c:\it\toolkit -Name

Example 6. PowerShell List all Files and Folder Details

To display all details of a file or folder use the fl option.

Get-ChildItem -path c:\it\toolkit | FL

You can see below this command will display additional details, if there are any.

Example 7. PowerShell count files and folders

To get a count of the files and folders use the measure-object option.

Get-ChildItem -path c:\it\toolkit | Measure-Object
powershell count folders

Example 8. Powershell Get Folder Size

You can also use the measure-object option to get the folder size.

Get-ChildItem -path c:\it\toolkit | Measure-Object -Property Length -sum
powershell get folder size

As you can see using PowerShell there are a lot of options when it comes to getting files and folders, you can create some really powerful reports.

Check out the Get-ChildItem documentation page to learn more.

Get Folder and Subfolder NTFS Permissions

If you need a report of folders and subfolders that includes who has permission to what, then check out the NTFS Permissions Reporting Tool below.

Example 1. List NTFS Permissions on Shared Folder

You can try this tool for FREE, click here to download it.

In this example, I’ll get the permissions on the shared folder \\srv-vm1\share

The NTFS Report will display the following:

  • DirectoryName = Path of the folder
  • Account = Account listed on the folder (this can be a user or group)
  • DirectoryOwner = Owner listed on the folder
  • DirectoryRights = Permissions the user or group has to the folder
  • Type = Allow or Deny
  • AppliesTo = What the permissions applies to
  • IsInherited = Are the permissions inherited from a parent folder

Example 2. List Folder Permissions on Local Folder

If you want to check the permissions on a local folder click the browse button or enter the folder path.

Which Command Will You Use?

In this article, I showed you three different commands to get files, folders, and subfolders.

I use the dir command for basic stuff and use Get-Childitem for more advanced searches.

Which command did you find most useful? Let me know in the comments below.

Related Articles

Leave a Comment