How to Delete Files from PowerShell

By | June 9, 2019

You can easily delete files from PowerShell by using command “Remove-Item”. This article helps to you how to delete a file this command as below. Just open PowerShell prompt and execute the command.

remove-item file-path

How to Delete Files from PowerShell
Example:

PS C:\> Remove-Item C:\test\testFile.txt PS C:\>

Read Also: How to Shutdown or Reboot Remote Computer from Command Line

How to Delete multiple files –

You can delete many files by this command and just need to add files name with separated by the comma. Looks below-

PS C:\> Remove-Item C:\dir1\file1, C:\dir1\file2, C:\dir2\file3
PS C:\>

Read Also: GCC is not Recognized as Internal or External Command

How to Remove files with wild characters –

You can also use wildcards too with “Remove-item” and delete files in bulk.

Remove-Item *.csv

If you use the above command and it deleted all files with csv extension. If the file does not exist, you will see an error when you command throw as shown below.

PS C:\> Remove-Item C:\dir1\FileThatDoesNotExist.txt
Remove-Item : Cannot find path 'C:\dir1\FileThatDoesNotExist.txt' because it does not exist.
At line:1 char:1
+ Remove-Item C:\dir1\FileThatDoesNotExist.txt
+ ~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (C:\dir1\FileThatDoesNotExist.txt:String) [Remove-Item], ItemNotFoundException
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.RemoveItemCommand

Read Also: How to Enable / Disable WiFi Connection

Leave a Reply

Your email address will not be published. Required fields are marked *