Managing folders
In this recipe, we will explore different cmdlets that support folder management.
How to do it...
Let's take a look at different cmdlets that can be used for folders.
Open PowerShell ISE. Go to Start | Accessories | Windows PowerShell | Windows PowerShell ISE.
Add the following script and run it:
#list folders ordered by name descending $path = "C:\Temp" #get directories only Get-Childitem $path | Where PSIsContainer #create folder $newFolder = "C:\Temp\NewFolder" New-Item -Path $newFolder -ItemType Directory -Force #check if folder exists Test-Path $newFolder #copy folder $anotherFolder = "C:\Temp\NewFolder2" Copy-Item $newFolder $anotherFolder -Force #move folder Move-Item $anotherFolder $newFolder #delete folder Remove-Item $newFolder -Force -Recurse
How it works...
The following are some cmdlets that support folder manipulation:
Cmdlet |
Description |
---|---|
|
Lists all directories in a path #get directories onlyGet-Childitem $path | Where PSIsContainer |
|