Windows cmd list folders

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

  • List Files and Folders using the DIR Command
  • Display Folder Structure using TREE Command
  • Powershell List Folders and Subfolders
  • Get Folder and Subfolder NTFS Permissions

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

  • PowerShell get NTFS Permissions
  • Windows list open files
  • 10 Windows File Share Best Practices

To list folders in the Command Prompt (cmd), you can use the `dir` command with the `/ad` option, which displays only directories.

dir /ad

Understanding CMD and Its Basic Commands

What is CMD?

Command Prompt, commonly referred to as CMD, is a command-line interface in Windows that allows users to execute commands and run programs through a text-based interface. Unlike the graphical user interface (GUI) that most people interact with daily, CMD gives you direct access to the computer’s file system and built-in utilities.

Why Use CMD for File and Directory Management?

Using CMD for managing files and directories provides significant advantages:

  • Speed and Efficiency: CMD is often faster than navigating through GUI interfaces, especially for experienced users who know the commands. With simple keystrokes, users can execute commands without sifting through multiple windows or menus.

  • Automation and Scripting Capabilities: CMD allows users to create scripts and batch files to automate repetitive tasks, such as backing up files or listing specific directories. This is particularly useful for system administrators or users with large databases of files.

List Users in Cmd: A Quick Guide for Beginners

List Users in Cmd: A Quick Guide for Beginners

Getting Started with CMD

Opening the Command Prompt

Accessing the Command Prompt is straightforward. Here’s how you can do it:

  1. Using Windows Search: Type «cmd» or «Command Prompt» into the search bar and press Enter.
  2. Using the Run Dialog: Press `Windows + R` to open the Run dialog, type `cmd`, and press Enter.

Tip: For administrative privileges, right-click on CMD in the search results and select «Run as Administrator.» This can give you access to more commands that require elevated permissions.

Basic Command Syntax

Understanding the basic command syntax can ease your journey into CMD. The general structure to remember is:

command [options] [path]
  • command: This is the command you want to run.
  • [options]: These are optional switches that modify how the command operates (e.g., `/ad` for listing directories only).
  • [path]: This specifies the target directory or file. If omitted, CMD will default to the current working directory.

List Files Cmd Windows: A Simple Guide

List Files Cmd Windows: A Simple Guide

Listing Folders in CMD

The `dir` Command for Directory Listings

The `dir` command is the primary way to list files and folders within a directory in CMD. It provides a comprehensive overview of all files and folders in the specified location.

Basic Usage

To use the `dir` command without any options, simply type:

dir

Executing this command will display all files and directories in the current directory. The output includes essential attributes like file size and date modified.

Listing Files and Folders

List Files in a Directory CMD

To list files within a specific directory, specify the folder path as follows:

dir C:\Users\YourUsername\Documents

This command shows all files and folders directly located in the “Documents” directory. The output will detail the items present, including their names, sizes, and dates.

List Folders Only

If you want to filter the output to see only directories, you can use the command with the appropriate switch:

dir /ad

The `/ad` switch tells CMD to display only directories. This is particularly useful when working in folders with many files and needing a cleaner view of just the folders.

Listing Files in a Folder CMD

Using Wildcards

Wildcards are powerful tools in CMD that can help you filter what you display. The asterisk `*` represents any group of characters, while the question mark `?` represents a single character.

For example, to list all `.txt` files in the current directory, use:

dir *.txt

This command will show every text file in the current folder, making it ideal for quickly identifying specific file types.

List Disks in Cmd: A Quick Guide to Disk Management

List Disks in Cmd: A Quick Guide to Disk Management

Advanced Listing Techniques

Sorting and Organizing Output

You can sort your directory listings using additional switches. For example, if you want to view files sorted by their last modified date with the most recent files first, you can use:

dir /O-D

Here, `/O` indicates sorting, and `-D` specifies the recent files appear first.

Saving Directory Listings to a File

Need to keep a record of your directory contents? You can easily redirect the output to a text file. To export your directory listing, type:

dir > directory_list.txt

This command saves the content of the current directory to a file named `directory_list.txt`. You can then open this file with any text editor to review your directory structure.

Create Folders Cmd Like a Pro: A Quick Guide

Create Folders Cmd Like a Pro: A Quick Guide

Helpful CMD Commands for Directory Management

Additional Directory Listing Commands

`tree` Command

The `tree` command provides a visual representation of the directory structure. It lists all directories and subdirectories in a tree-like format.

To use it, type:

tree C:\Users /F

The `/F` switch adds file names to the output. This is a useful command for getting a quick overview of a directory hierarchy.

`ls` Command (Using Windows Subsystem for Linux)

For users who have installed the Windows Subsystem for Linux (WSL), the `ls` command can also be used to list folders. Although similar in functionality to the `dir` command, many users find `ls` to be more aligned with Unix-like systems.

Using `cd` to Navigate

Before listing folders, you might need to navigate through your directories. The `cd` (change directory) command allows you to do just that.

cd C:\Users\YourUsername\Documents

This command takes you directly to the specified “Documents” folder, where you can then use the `dir` command to list contents or navigate further.

Open Files in Cmd: A Simple Guide for Quick Access

Open Files in Cmd: A Simple Guide for Quick Access

Troubleshooting and Tips

Common Issues and Fixes

When using CMD, you may encounter some common issues. For instance:

  • If CMD does not recognize a command, ensure you are typing it correctly, including correct paths and syntax.
  • If you receive permission errors, try running CMD as an administrator.

Best Practices for CMD Usage

To enhance your experience with CMD, consider these best practices:

  • Stay Updated: Occasionally, check CMD documentation or resources for updates or new commands.
  • Learn Keyboard Shortcuts: Get familiar with CMD shortcuts, such as using the Tab key for autocomplete, to enhance your efficiency.

Copy Folder Cmd: A Quick Guide to Mastering Copying Folders

Copy Folder Cmd: A Quick Guide to Mastering Copying Folders

Conclusion

Listing folders in CMD opens up a world of possibilities for managing files and directories efficiently. By mastering commands like `dir`, `cd`, and `tree`, you can significantly improve your productivity. Practice these commands regularly, and don’t hesitate to explore more advanced CMD tutorials to expand your skills further.

  • Home
  • Partition Magic
  • CMD List Files: How to List Files in Command Prompt Windows 10/11

By Ariel | Follow |
Last Updated

What command can be used to list files in a directory? How to list files in Command Prompt Windows 10/11? A great many people are confused about these questions. In this post, MiniTool explains the Command Prompt list files topic in detail and introduces an alternative to CMD list files.

CMD (Command Prompt) is a powerful Windows built-in tool that can be used to do many works such as CMD copy files, CMD list drives, CMD WiFi password, and more. However, a lot of users don’t how to list files in Command Prompt. Here’s a true example from the StackOverflow forum:

I tried searching for a command that could list all the files in a directory as well as subfolders using a command prompt command. I have read the help for the «dir» command but couldn’t find what I was looking for. Please help me with what command could get this.

https://stackoverflow.com/questions/15214486/command-to-list-all-files-in-a-folder-as-well-as-sub-folders-in-windows

Although there are already many discussions and posts about the Command Prompt list files, most of them lack clear steps and screenshots, which makes people difficult to understand the “CMD list files” operation. Thus, we want to write a complete guide to explain it. Let’s keep reading.

What Command Can Be Used to List Files

To list directory CMD smoothly, you need to know what command can be used to list files in a directory Windows first. The answer is to use the DIR command. This command can be used to show all files and subfolders in the current directory. In addition, it displays the file name, size, and last modification date of each file like File Explorer.

The DIR command is available in CMD for almost all Windows systems, including Windows 11/10/8/7/Vista/XP. Here are the most commonly used command lines about the CMD list directory/files:

  • D: List all directories in the current path
  • R: Show read-only files
  • H: Show hidden files
  • A: Archive files
  • S: List system files
  • I: Not content indexed files
  • L: Reparse points
  • -: Add a minus in front of any of the file attribute to let the DIR command not show that kind of file.

How to List Files in Command Prompt Windows 10/11

How to list files in CMD Windows 10/11? The answer depends on what files you want to list. Here we summarize several common examples of the Windows Command Prompt list files.

Step 1. First of all, you need to navigate to the directory in which you want to list files in File Explorer.

Step 2. Click on the address bar and type cmd in the file path and hit Enter, which will open the Command Prompt window.

Tips:

Also, you can locate the directory first in File Explorer, and then press the Win + R keys to open the Run box, type cmd in it, and hit Enter to open the Command Prompt window.

type cmd in the address bar of File Explorer

Step 3. In the pop-up window, you can list file CMD according to your needs. For example:

Example 1. CMD List all directories and folders under the current path.

dir

run dir in the cmd

Example 2. CMD List folders of the current directory only.

dir /ad

run dir ad

Example 3. CMD list files only under the directory.

dir /a-d

cmd list files only

Example 4. CMD list files and folders under a specific directory (e.g. C:Usersdefaultuser1)

cd C:Usersdefaultuser1

dir

CMD list files of a specific directory

Example 5. CMD list all system files under the directory.

dir /s

CMD list system files

Example 6. CMD list all read-only non-achieve files.

dir /a:r-a

CMD list read only files

Example 7. CMD list all files with the file extension .doc.

Tips:

You can replace the doc with other file extensions such as exe, png, xml, etc.

dir *.doc

CMD list files with doc extension

Example 8. CMD list all files with the file extension .doc and .jpg.

dir *.doc *.jpg

CMD list files with doc and jpg extension

Of course, there are many other dir commands to list file CMD on Windows 10/11 and we can’t explain all in this post. If you want to know more information about Windows CMD list files, you can search for corresponding commands online on Google.

Better Alternative to Command Prompt List Files

Although you can list files in a directory CMD, many professional commands might be unfamiliar to you. How to list all files/folders under a directory more easily? MiniTool Partition Wizard is a better alternative to Windows Command Prompt list files.

Its Space Analyzer feature can show all files/folders under a specific path in the file name, size, last change, extension, percentage of drive, etc. In addition, it tells you what files are taking up your disk space and helps you free up disk space.

MiniTool Partition Wizard FreeClick to Download100%Clean & Safe

list files using MiniTool Partition Wizard

About The Author

Position: Columnist

Ariel has been working as a highly professional computer-relevant technology editor at MiniTool for many years. She has a strong passion for researching all knowledge related to the computer’s disk, partition, and Windows OS. Up till now, she has finished thousands of articles covering a broad range of topics and helped lots of users fix various problems. She focuses on the fields of disk management, OS backup, and PDF editing and provides her readers with insightful and informative content.

  • Use the “DIR” command to list files and folders in the current directory, or “DIR /S” to list files and folders recursively, in subdirectories as well.
  • To search for specific file types use the asterisk followed by the file extension type, in this syntax: DIR *.jpg
  • Use attribute switches to filter the type of files and folders to list.

It can be tricky to keep tabs on all files and folders on a Windows computer, especially if there are too many. There can be many folders and subfolders inside a partition, and many different types of file extensions. It can be difficult to view all the files and folders, or even search for specific ones using File Explorer.

Using the Command Prompt, you can view and list all sorts of files and folders inside a directory, and even its subdirectories using recursive switches. Not only that, but you can also list all items with a specific file type, or exclude them. Moreover, you can also view hidden items as well directly from the Command Prompt.

In this article, we give you a bunch of different examples to list files and folders inside the Command Prompt using the DIR cmdlet.

Command to List Files and Folders in Command Prompt

The DIR command is used to list files and folders inside a directory in Command Prompt. This command can be used with a number of switches and attributes to filter the items to display, their order or displaying, to include and exclude, and so on.

However, the only switches we will be interested in are /a and /s.

Using the DIR command alone will display all the files and folders inside that particular directory. It will not show any hidden items, and it will now show any items inside the subdirectories. However, if you use DIR /a, it will show the hidden items as well.

To perform a recursive search, we must use the /s switch.

The table below summarises the commands to use to list files and folders and these switches:

Command Description
DIR Display items inside the current directory
DIR /a Display all items inside the current directory, including hidden ones.
DIR /s List items inside the current directory as well as all subdirectories
Commands to list files and folders using Command Prompt

With that known, there is a list of attributes that you can use with the DIR /a cmdlet to filter the type of information you want to list. Here is a list of the attributes you can use with /a.

Attribute Alphabet Description Syntax Example
d Shows directories only DIR /ad
h Show hidden items only DIR /ah
s Show system files only DIR /as
l Show reparse points only DIR /al
r Show read-only files DIR /ar
a Show files that can be archived DIR /aa
i Show files whose content is not indexed DIR /ai
– (hyphen) Used before an attribute to exclude it from the list DIR /a-s (hide system files)
: (colon) To combine multiple attributes DIR /a:h-s (Show hidden items but hide system files)
Command Prompt syntaxes to list files and folders using attributes

Example Commands to List Files and Folders in Command Prompt

Let us now continue to see more extensive examples with images to better understand how you can list files and folders using the DIR cmdlet.

  • To list all files and folders in the current directory:

    DIR
    List files and folders in the current directory using Command Prompt

    List files and folders in the current directory using Command Prompt
  • To list all files and folders in the current directory and subdirectories:

    DIR /S
    List recursive files and folders in Command Prompt

    List recursive files and folders in Command Prompt
  • To list only folders in the current directory:

    DIR /AD
    List only folders in the current directory in Command Prompt

    List only folders in the current directory in Command Prompt
  • To list only folders in the current directory and subdirectories:

    DIR /AD /S
    List only folders in the current directory and subdirectories in Command Prompt

    List only folders in the current directory and subdirectories in Command Prompt
  • To list all files in the current directory and exclude all folders:

    DIR /A-D
    List all files and exclude folders in current directory in Command Prompt

    List all files and exclude folders in the current directory in Command Prompt
  • To list all hidden system files in the current directory:

    DIR /ASH
    List all hidden system files in current directory in Command Prompt

    List all hidden system files in current directory in Command Prompt
  • To list all system files and exclude read-only files in the current directory and subdirectories:

    DIR /A:S-A /S
    List all system files and exclude read only files in the current directory and subdirectories using Command Prompt

    List all system files and exclude read-only files in the current directory and subdirectories using Command Prompt
  • To list all specific file type files in the current directory and subdirectories:

    Note: You can change the file type extension to list the files you are looking for.

    DIR *.txt
    List all files with a specific file type using Command Prompt

    List all files with a specific file type using Command Prompt
  • To list multiple file types in the current directory and subdirectories:

    DIR *.txt *.doc *.docx /S
    List multiple file types in the current directory and subdirectories from Command Prompt

    List multiple file types in the current directory and subdirectories from Command Prompt

There can be many different examples and syntaxes to list files and folders inside the Command Prompt. However, we hope that the examples above are sufficient so that you can combine and modify them as per your requirements.

Closing Words

The Windows command line offers much more control over the fetched data than its GUI. Using the Command Prompt, you can list different files and folders inside the current directory as well as its subdirectories. You can also filter out the type of files and folders to include, or exclude from the list.

The dir command is used to list files and folders in the Windows command prompt (CMD).

dir

The dir command without a path will display a list of files and folders in the current working directory.

DIR Command - List Files in Windows Command Prompt

You can provide a path to see the listing for a different directory:

dir C:\Windows

By default, the dir command does not show hidden files and folders. To include hidden files, run the dir command as follows:

dir /a

You can use the /B switch to show the file names only without heading information or summary.

dir /b C:\Windows

The /s option lists all files in a specified directory and all subdirectories.

dir /s

List Files Using Patterns

The dir command supports wildcard character (*) that you can use to describe a pattern to match.

For example, the following command lists all files that begin with the letter A:

dir a*

Here is another example that lists all files that have a .doc extension:

dir /b *.doc

Displays files with specified attributes

The /A switch is used to list files and folders with specified attributes. For example, the letter H represents the hidden attribute.

dir /a:h

The following table describes each of the values that you can use for Attributes.

D Folders.
H Hidden files and Folders.
S System files.
L Reparse Points.
R Read-only files.
A Files ready for archiving.
I Not content indexed files.
O Offline files.
Prefix meaning not (See examples).

Examples

List Files and folders in C:\Windows\System32 directory:

dir C:\Windows\System32

Obtain a listing of all files in C:\Windows\System32 that ends with the .txt extension:

dir C:\Windows\System32\*.txt

Search for files with .dll extension in C:\Windows\System32 and all subdirectories:

dir /s C:\Windows\System32\*.dll

Returns the listing for the parent directory of the current working directory:

dir ..

List all files and folders, including hidden files:

dir /a

Show hidden files only:

dir /a:h

List only folders:

dir /a:d

Don’t list folders:

dir /a:-d

Show only hidden folders:

dir /a:dh

List read only files:

dir /a:r

Sort the result by name:

dir /o:n

This will sort the result set by size:

dir /o:s

Sort the result set by size (largest first):

dir /o:-s

Sort the result by date:

dir /o:d

Includes the name of the owner for each file:

dir /q

Show creation time:

dir /t:c

Show last access time:

dir /t:a

Show the last written time:

dir /t:w

Run the dir /? command to see a list of all the available command-line options.

Понравилась статья? Поделить с друзьями:
0 0 голоса
Рейтинг статьи
Подписаться
Уведомить о
guest

0 комментариев
Старые
Новые Популярные
Межтекстовые Отзывы
Посмотреть все комментарии
  • Lenovo ideapad miix 10 windows 10
  • Как удалить iis windows server 2016
  • Acer aspire 3 настройка биос под установку windows 10
  • Windows vista icons for windows 10
  • Панель быстрого доступа windows 10 где находится