July 14, 2026

How to Delete a Folder and Its Contents with PowerShell

Deleting a folder along with everything inside it can be done in one PowerShell command, which is useful when a folder has many files and subfolders you no longer need. This is quicker than emptying a folder manually, but because YYGACOR it removes everything, it is worth understanding exactly what the command does.

The Command

Remove-Item -Path "C:\Path\To\Folder" -Recurse -Force

What It Does

`Remove-Item` deletes the item at the path you specify. The `-Recurse` parameter tells it to include everything inside the folder, meaning all files and subfolders, rather than just the folder itself. The `-Force` parameter allows it to remove hidden or read-only items that would otherwise be skipped. Together, these delete the entire folder and its contents in one step.

When You’d Use This

Reach for this when a folder holds many files and subfolders you want gone in one step, such as clearing an old project, an emptied download batch, or a temporary working directory. It is far quicker than opening the folder and deleting everything by hand, and it fits naturally into cleanup scripts that remove folders as part of a routine.

Useful Variations

To delete only the contents but keep the folder itself, target everything inside with a wildcard: `Remove-Item -Path “C:\Path\To\Folder\*” -Recurse -Force`. If you want to be asked to confirm before each deletion, leave off `-Force` and add `-Confirm`. To preview what would be removed without actually deleting anything, add `-WhatIf` to the end of the command.

If It Doesn’t Work

If you see an access-denied error, add `-Force`, which the example already includes, to handle read-only or hidden items, and run PowerShell as administrator for protected locations. If a file is in use by a running program, close that program first, since locked files cannot be deleted. If the path is wrong, PowerShell reports it cannot find the item, so double-check the folder path before running again.

Good to Know

This deletes items permanently rather than moving them to the Recycle Bin, so double-check the path before running it. Using `-WhatIf` first is a good habit when you are unsure, since it lists exactly what the command would remove without touching anything.

Putting It Together

The command shown may look dense at first, but it breaks down into clear parts once you have used it a few times. As part of managing files from the terminal, this command earns its place once you are comfortable working without File Explorer. Combined with the others in this area, it lets you handle files in bulk and in scripts far faster than clicking through folders. Like anything in the terminal, the real value comes from trying it on your own system and adapting the variations above to what you actually need, so it is worth experimenting with in a safe, low-stakes situation before relying on it in a script or during troubleshooting. Keeping a note of the commands you find most useful, along with the variations that fit your workflow, turns scattered one-off tricks into a personal reference you can draw on whenever a similar task comes up again.