What is the simplest way to forcefully delete a directory and all its subdirectories in PowerShell? I am using PowerShell V2 in Windows 7.
I have learned from severa
Another useful trick:
If you find a lot of files with same or similar name convention (like mac file with dot prefix name... that famous file pulltion), you can easily remove them with one single line from the powershell like this:
ls -r .* | rm
This line is going to remove all files with a dot in the begining of the name inside the current directory, and all files with same circumstances inside other folders inside this directory too. Be aware about it when using it. :D
I used:
rm -r folderToDelete
This works for me like a charm (I stole it from Ubuntu).
Really simple:
remove-item -path <type in file or directory name>, press Enter
To delete the complete contents including the folder structure use
get-childitem $dest -recurse | foreach ($_) {remove-item $_.fullname -recurse}
The -recurse
added to remove-item
ensures interactive prompts are disabled.
rm -r ./folder -Force
...worked for me
If you're committed to powershell, you can use this, as explained in the accepted answer:
rm -r -fo targetDir
But I've found it to be faster to use Windows Command Prompt
rmdir /s/q targetDir
In addition to being faster, another advantage to using the command prompt option is that it starts deleting files immediately (powershell does some enumeration first), so if something breaks while it's running, you've at least made some progress in deleting files.