Quick Links
Summary
PowerShell offers a straightforward way to delete files and folders on your Windows 11 or Windows 10 PC. you may remove folders, all files inside a folder, specific files from the specified directory, and so on using just a few commands. Here’s how to do that.
Before You Begin: How to Find a File or Folder’s Full Path
To remove files or folders from your Windows PC, you’ll need the item’s full path. If you knowhow to get file or folder paths, skip to the relevant section below. If you aren’t sure how to copy a file or folder’s full path, we’ll show you how.
First,open a File Explorer windowand locate the file or folder whose path you want to find. Then, hold down the Shift key on your keyboard, right-click your file or folder, and choose “Copy as Path.”
You’ve successfully copied the selected item’s path to your clipboard. You can nowpaste this path(using Ctrl+V) wherever required within the PowerShell window.
How to Delete a Specific File Using PowerShell
To remove a specific file from your PC, use PowerShell’s “Remove-Item"cmdlet.
Start byopening a PowerShell window on your PC. Here, type the following command, replace “PATH” with the full path to the item you want to delete, and press Enter:
As an example, to delete a file named “Old-List.txt” on your desktop, you’d run:
Note that the command won’t ask for a confirmation before deleting your file. If you’d like the command to do that, add the “Confirm” parameter as follows:
How to Delete a Specific Folder Using PowerShell
you’re able to use PowerShell’s “Remove-Item” cmdlet to remove any directory from your PC.
Deleting a folder removes all the subfolders and files inside it.
To start, launch PowerShell, type the following command, replace “PATH” with your directory’s full path, and press Enter:
As an example, to delete a directory named “Old Files” from your desktop, you’d run:
How to Delete All Files in a Folder But Keep the Folder
If you want to remove all files from a folder but retain the folder, use the “Remove-Item” cmdlet as follows.
In your PowerShell window, type the following command, replace “PATH” with the full path to the folder you want to empty, add “*.*” before the final quotation mark, and press Enter:
For example, to delete all files from a folder named “Your Files” from the desktop, run:
In this command, the first asterisk selects files with any name, and the second asterisk chooses files with any extension. This translates to selecting all the files in the specified folder.
How to Delete All Files From a Folder and Its Subfolders
If you’re looking to remove all files from a folder and its subfolders, add the “Recurse” and “Include” parameters to the “Remove-Item” cmdlet.
Open a PowerShell window, enter the following command, replace “PATH” with the full path to the folder, and press Enter:
Here, the “Recurse” parameter ensures the subfolders’ files are deleted as well. The “Include” parameter ensures files with any name and extension are removed.
As an example, to remove all files from the “Downloads” folder and its subfolders on the desktop, run:
How to Delete Files With Wildcards
PowerShell offers wildcards, allowing you to delete various kinds of files by just specifying those file types in your command. In all the examples below, replace “PATH” with the full path to your folder.
For example, if you want to remove all theJPGfiles from a folder, use the following command:
Another use of wildcards is to delete all but a specific file type from your directory. For example, to remove all files except forPDFfiles from a folder, use the following command:
Another advanced use of PowerShell is to remove all empty folders from the given directory. In this case, use the following command, replacing “PATH” with the full path to the directory:
And you’re set.
Now that you know how to delete items with PowerShell, you won’t be stuck when File Explorer refuses to work. PowerShell offers more ways than File Explorer to help you remove content, like the ability to only remove specific files with a single command.