Use PowerShell to Delete a Single File or Folder
Before start executing the Delete powershell command we need to make sure you are logged in to the server or PC with an account that has full access to the objects you want to delete.
1 2 |
# Using PowerShell commnads to delete a file Remove-Item -Path "C:\dotnet-helpers\DummyfiletoDelete.txt" |
The above command will excute and delete the “DummyfiletoDelete.txt” file which present inside the “C:\dotnet-helpers” location.
Use PowerShell to Delete all File and Folders inside the folder
We can also use wildcard ‘*’ characters to remove multiple items. For example, this command removes all the files in “C:\dotnet-helpers\*.*”
1 2 |
# Using PowerShell commnads to delete all file Remove-Item -Path "C:\dotnet-helpers\*.*" |
1 2 |
# Using PowerShell commnads to delete all file and folders Remove-Item -Path "C:\dotnet-helpers\*.*" -recurse |
Recurse drills down and finds lots more files. The โrecurse parameter will allow PowerShell to remove any child items without asking for permission. Additionally, the โforce parameter can be added to delete hidden or read-only files.
Using -Force command to delete files force fully
1 2 |
# Using PowerShell commnads to delete all file force fully Remove-Item -Path "C:\dotnet-helpers\*.*" -Force |
The above command will delete all hidden or read-only files from the location “C:\dotnet-helpers\”
Leave A Comment