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 as an administrator.
- Add the following script and run it:
#list folders ordered by name descending $path = "C:\Temp" #get directories only Get-Childitem $path | Where-Object 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...
Here are some cmdlets that support folder manipulation:
Cmdlet |
Description |
---|---|
|
This lists all directories in a path: #get directories only Get-Childitem $path | Where PSIsContainer |
|
This... |