Eight useful tips on how to manage files in Windows’ command prompt.
Managing files in Windows is usually done through File Explorer, but there are situations where a graphical interface isn’t the fastest or most flexible option. For advanced users, IT professionals, or anyone troubleshooting system issues, the Command Prompt provides a powerful way to work directly with files and folders using text-based commands.
Why Use the Command Prompt for File Management?
The Command Prompt allows you to perform file operations quickly and precisely, often with fewer steps than using menus and mouse clicks. Tasks like copying large numbers of files, deleting stubborn folders, or navigating deeply nested directories can be faster and more reliable when handled through commands.
Another advantage is control. The Command Prompt gives you access to operations that aren’t always exposed in the standard Windows interface, which can be especially useful when dealing with system files or recovering from errors. However, because commands execute immediately, it’s important to understand what each one does before using it.
In the sections below, we’ll cover the most common file and folder management commands, explain how they work, and show you how to use them safely and effectively.
Launching Command Prompt
The easiest way to open Command Prompt is by using the Run function. Hit the Windows key + R at the same time and you’ll see a pop-up window. In the Open bar, type cmd and click ok. This will open the main window of Command Prompt.
From here, you can type any commands you want. To make using Command Prompt easier, you’ll want to learn how to use the function key shortcuts. Function keys F1–F9 perform certain actions that often come in handy. Here’s what they are:
- F1 – Retypes the last command, character by character per each press.
- F2 – Asks for a specific character and retypes the last command until the selected character first occurs.
- F3 – Retypes the last command in full.
- F4 – Asks for a character, after which it deletes all characters in the command. The characters are deleted starting from the position of the cursor until the asked character occurs.
- F5 – Retypes previously used commands without cycling.
- F6 – Types ^Z in the command.
- F7 – Shows previously used commands.
- F8 – Retypes previously used commands with cycling.
- F9 – Retypes a used command in full, corresponding to the number of the command in the menu pulled up by F7.
Now that you know the basics, let’s take a look at some of the main file management commands.
1. Creating a File
To create a new file in Command Prompt, type the following command:
fsutil file createnew filename.txt 1000
The parameters to keep in mind here are the filename, extension, and size. You can name the file as you wish and create any file type. In this example, the file size would be 1000 KB. By entering the desired value, you’re telling Windows to create the file that requires that much space on your drive.
2. See All Files in a Directory
Command: dir
Typing dir into the Command Prompt will let you see all the files that are currently within the directory you’re in. This can be useful in many situations, especially when you want to see the extensions that can be accessed from the folder.
3. Show All Files Organized by Folders
Command: tree
When you navigate to a directory, just type tree in the Command Prompt and you’ll see all your files within their corresponding folders. This gives you a clear overview of all the files in a directory and make file navigation easy.
4. Change All File Extensions in a Folder
Command: rename
If you need to change the type of all the files within a folder, you can do so in no time in Command Prompt. For example, if you have a folder where all images are in .png, you can change them to .jpeg or any other image type with the rename command.
Just type rename *.png*.jpeg and all your images will have a .jpeg extension.
5. Show Hidden Files
To uncover all hidden files and folders within a directory, use the following command:
dir /A:H /B
You can also do this for the hidden files and folders in a directory’s subfolders with the command below:
dir /s /b /A:DH
If you want to hide a file, you can do so by entering the following:
attrib +s + h file_name
When you do this, the file will be invisible in normal view, even with the Show Hidden Files option. The only way to make the file visible again is to enter the following line:
attrib -s -h file_name
6. Copy and Paste Files
You can copy files from one folder to another by entering the following command:
Xcopy /I Source_folderDestination_folder
If you want to copy all files along with the subfolders, type in:
Xcopy /S /I /E Source_folder Destination_folder
7. Scan Files for Viruses
This is a neat command that everyone should use every once in a while, even if they have a good antivirus software. To do this, you need to run the Command Prompt as administrator, which you can do by right-clicking the shortcut and then clicking Run as administrator.
Once you’ve done this, just type sfc /scannow and all the files inside a directory will be checked for viruses and other corruptions.
8. Wipe an Entire Drive
As you might know, the files you delete by using the regular methods are never gone for good. There are many ways to recover them, even years after the deletion. Using the cipher command is the only way to completely wipe the whole drive. For example, if you want to clean the D drive, type in cipher /w:D:\.
Keep in mind that once you do this, the files are unrecoverable, so only do it if you’re certain that you want to erase all data from a drive.
Quick-Reference: Common File Management Commands
This table provides a quick overview of commonly used Command Prompt commands for managing files and folders.
| Command | What It Does | Example |
|---|---|---|
dir |
Lists files and folders in the current directory | dir |
cd |
Changes the current directory | cd Documents |
mkdir |
Creates a new folder | mkdir Backup |
rmdir |
Deletes an empty folder | rmdir OldFolder |
copy |
Copies one or more files | copy file.txt D:\Backup |
xcopy |
Copies files and directories, including subfolders | xcopy C:\Data D:\Data /E |
move |
Moves files or folders | move file.txt D:\Archive |
del |
Deletes one or more files | del temp.txt |
ren |
Renames a file or folder | ren old.txt new.txt |
Tip: You can type command /? (for example, copy /?) to see available options and switches.
Important Warning About Destructive Commands
Some Command Prompt commands make permanent changes immediately and do not send files to the Recycle Bin. Commands such as del, rmdir, and xcopy with certain switches can permanently remove files or entire directories if used incorrectly.
Before running any command that deletes, moves, or overwrites data:
- Double-check the file path and folder name
- Avoid using wildcards (
*) unless you are certain of the result - Test commands on non-critical files first
- Make sure important data is backed up
Using the Command Prompt carefully helps you take advantage of its speed and power without risking accidental data loss.
Using the Command Prompt Confidently and Safely
The Command Prompt is a powerful tool, but with that power comes responsibility. Simple mistakes — such as deleting the wrong directory or running commands without checking paths — can lead to data loss or system issues. Taking time to understand commands and test them carefully can help prevent problems.
For everyday users, the Command Prompt may only be needed occasionally. For others, it can become an essential part of managing and troubleshooting Windows. By learning the basics and using commands thoughtfully, you can take advantage of its speed and flexibility without putting your system at risk.