How to List All Files in a Directory with Detailed Information Using Command Prompt

Introduction

Learn how to list all files in a directory with detailed information such as file sizes, dates, and attributes using the Command Prompt in Windows. This step-by-step guide will help you save the output to a text file for easy reference.

Step 1: Open Command Prompt

  1. Press the Windows key on your keyboard or click the Start button.
  2. Type cmd in the search bar.
  3. Click on Command Prompt from the search results to open it.

Step 2: Navigate to the Directory

  1. In the Command Prompt window, you need to navigate to the directory you want to list.
  2. Use the cd (change directory) command followed by the path to your directory. For example:
    cd C:\Users\YourName\Documents
    
  3. Press Enter.

Navigating in Command Prompt

  • To go up one directory level: Use cd ..
    cd ..
    
  • To go to the root directory: Use cd \
    cd \
    
  • To list the contents of the current directory: Use dir
    dir
    

Step 3: List Files with Detailed Information

  1. Type the following command:
    dir /a /c /d /l /n /o /p /q /s /t:c /w /x /4 > filelist.txt
    
  2. Press Enter.

Step 4: Understand the Command

  • dir: The command to list directory contents.
  • /a: Displays files with specified attributes.
  • /c: Displays the thousand separator in file sizes.
  • /d: Uses wide list format, but files are sorted by column.
  • /l: Uses lowercase.
  • /n: Uses new long list format where filenames are on the far right.
  • /o: Sorts the output.
  • /p: Pauses after each screen of information.
  • /q: Displays the owner of the file.
  • /s: Lists every occurrence of the specified file name within the specified directory and all subdirectories.
  • /t:c: Uses creation time for sorting.
  • /w: Uses wide list format.
  • /x: Displays the short names generated for non-8dot3 file names.
  • /4: Displays years in four-digit format.
  • > filelist.txt: Redirects the output to a file named filelist.txt.

Step 5: Locate the Output File

  1. After running the command, a file named filelist.txt will be created in the same directory.
  2. Open File Explorer and navigate to the directory you listed.
  3. Find and open filelist.txt to see the detailed list of all files and directories.

Conclusion

By following these steps, you will create a comprehensive list of all files and directories, including their attributes, sizes, and other details, and save it to a text file. This method is useful for keeping records or sharing directory contents with others.