Once can navigate file system, add file management Cmdlets
New-Item -Path MyNewFolder -ItemType Directory
New-Item -Path “TestFile1.txt” -ItemType file
New-Item -Path “TestFile2.txt”,”TestFile3.txt”,”TestFile4.txt” -ItemType file
New-Item -Path TestFileWithContent.txt -ItemType file -Value “This is my file content”
Rename
Rename-Item -Path TestFile1.txt -NewName TestFileOne.txt
Copy
Copy-Item -Path TestFile2.txt -Destination .\Copies\
Copy-Item -Path .\Test-Files\* -Destination .\Copies\
Move
Move-Item -Path TestFile3.txt -Destination ~\Downloads\
The file Cmdlets will work with ONLY the First Level of a folder
You can include all nested items, with a “Recurse” parameter
LS Temp
LS Temp -Recurse
This works with other file Cmdlets, like Copy
To Copy ALL the contents, of all subfolders – use the -Recurse parameter
Copy-Item -Path C:\Users\lenny\Documents\Temp\ -Destination .\Copies\
Copy-Item -Path C:\Users\lenny\Documents\Temp -Destination .\Copies\ -Recurse
BIG WARNING!!!!!
This Cmdlet bypasses the Recycle Bin
You won’t be able to undo these deletes
Remove-Item -Path TestFile3.txt
Remove-Item -Path Copies
Can also – add the -Recurse parameter to avoid the prompt
Example of using file Cmdlets to organize a folder
Get list of extensions
LS | Select Extension | Sort -Property Extension -Unique
New-Item -Path "doc","ppt","txt","xls" -ItemType Directory
LS "*doc" -File | Move-Item -Destination .\doc
LS "*ppt" -File | Move-Item -Destination .\ppt
LS "*txt" -File | Move-Item -Destination .\txt
LS "*xls" -File | Move-Item -Destination .\xls
LS . -Recurse
Note: there are other ways to do “repeatable” commands – using Loops
will explore MUCH more in Intermediate class
Quick Example using Test-Files2