Dir command with creation time and last modified time
Categories:
Mastering dir
Command: Displaying Creation and Last Modified Times

Learn how to use the Windows dir
command to view file and directory creation and last modified timestamps, enhancing your command-line file management skills.
The dir
command in Windows Command Prompt is a powerful utility for listing the contents of directories. While its basic usage provides file names, sizes, and last modification dates, many users need more specific timestamp information, such as the creation date or the last access date. This article will guide you through various dir
command options to extract these crucial timestamps, helping you better track file changes and origins.
Understanding File Timestamps in Windows
Windows maintains several timestamps for each file and directory, which are essential for auditing, backup, and general file management. The three primary timestamps are:
- Creation Time: The date and time when the file or directory was originally created on the file system.
- Last Modified Time (Write Time): The date and time when the file's content was last changed. This is the most commonly displayed timestamp by default.
- Last Access Time: The date and time when the file was last read or accessed. This timestamp is often disabled by default on modern Windows versions for performance reasons, as updating it for every read operation can be resource-intensive.
flowchart TD A[File/Directory] --> B{"Has Timestamps?"} B -- Yes --> C[Creation Time] B -- Yes --> D[Last Modified Time] B -- Yes --> E[Last Access Time] B -- No --> F[Error/Not Found] C --> G[Origin/Initial State] D --> H[Content Changes] E --> I[Read/Opened Activity] G & H & I --> J[File History]
Flowchart illustrating the different types of file timestamps and their significance.
Displaying Creation Time with dir
By default, dir
displays the last modified time. To include the creation time in your directory listing, you need to use the /TC
switch. This switch tells dir
to sort and display files by their creation time. While it sorts by creation time, it also shows the creation time in the output column that usually displays the last modified time.
dir /TC
Basic dir
command to display creation time.
This command will list files and directories, showing their creation date and time in the date column. If you want to see both creation time and last modified time, you'll need to combine dir
with other tools or parse the output, as dir
itself doesn't offer separate columns for both simultaneously in a single view.
Displaying Last Modified Time (Default Behavior)
The last modified time is the default timestamp shown by the dir
command. You don't need any special switches for this, but for clarity or to ensure it's explicitly used, you can use the /TW
switch (Time Write). This switch sorts by write time, which is the last modified time.
dir
dir /TW
Commands to display last modified time (default and explicit).
Advanced Usage: Combining Switches and Filtering
You can combine various dir
switches to get more refined output. For instance, to list all files and subdirectories (/S
), in a wide format (/W
), showing creation time (/TC
), and pausing after each screen (/P
), you would use:
dir /S /W /TC /P
To filter by date, you can use the /A
switch with specific attributes, but dir
doesn't directly support filtering by a date range for creation or modification time without piping its output to findstr
or using PowerShell. For example, to find files created after a certain date, PowerShell is generally more suitable.
Get-ChildItem
cmdlet, which offers much greater flexibility in accessing and formatting file properties, including CreationTime
, LastWriteTime
, and LastAccessTime
.Get-ChildItem -Path "." | Select-Object Name, CreationTime, LastWriteTime, LastAccessTime
PowerShell command to display all timestamps for items in the current directory.
Practical Examples and Use Cases
Understanding and utilizing these timestamps can be incredibly useful:
- Troubleshooting: If a system is behaving unexpectedly, checking the creation time of configuration files can reveal if a recent installation or change introduced the issue.
- Security Auditing: Identifying files created or modified outside of expected hours can indicate suspicious activity.
- Backup Verification: Comparing creation and modification times can help verify if backup processes are correctly capturing the latest versions of files.
- Data Recovery: When recovering files, knowing the creation time can help prioritize which versions to restore.
1. Open Command Prompt
Press Win + R
, type cmd
, and press Enter
.
2. Navigate to Target Directory
Use the cd
command (e.g., cd C:\Users\YourUser\Documents
) to go to the directory you want to inspect.
3. List with Creation Time
Execute dir /TC
to see files and folders sorted by and displaying their creation time.
4. List with Last Modified Time
Execute dir
or dir /TW
to see files and folders sorted by and displaying their last modified time.