- PowerShell Tutorial
- PowerShell - Home
- PowerShell - Overview
- PowerShell - Environment Setup
- PowerShell - Cmdlets
- PowerShell - Files and Folders
- PowerShell - Dates and Timers
- PowerShell - Files I/O
- PowerShell - Advanced Cmdlets
- PowerShell - Scripting
- PowerShell - Special Variables
- PowerShell - Operators
- PowerShell - Looping
- PowerShell - Conditions
- PowerShell - Array
- PowerShell - Hashtables
- PowerShell - Regex
- PowerShell - Backtick
- PowerShell - Brackets
- PowerShell - Alias
- PowerShell Useful Resources
- PowerShell - Quick Guide
- PowerShell - Useful Resources
- PowerShell - Discussion
Powershell - Delete File
Cmdlet
Remove-Item cmdlet is used to delete a file by passing the path of the file to be deleted.
Example 1
In this example, we'll delete a file D:\Temp\Test Folder\Test.txt
Type the following command in PowerShell ISE Console
Remove-Item 'D:\temp\Test Folder\test.txt'
You can see the Test Folder1 in Windows Explorer is deleted now.
Example 2
In this example, we'll remove the folder D:\Temp\Test Folder recursively deleting its all files. In first example, PowerShell confirms if directory is not empty. In this case, it will simply delete the item.
Type the following command in PowerShell ISE Console
Remove-Item 'D:\temp\Test Folder' -Recurse
You can see the content of temp folder in Windows Explorer where its folder is now removed.
powershell_files_folders.htm
Advertisements