Making and Moving

Make folders and files, then copy, move and rename them, many at a time.

Updated

Making

  1. Making Folders and Files: New-Item (Novice): New-Item makes new folders and files where you say, several at once or a whole path of folders in one go, -Value puts text into a new file, and -Force means "it's fine if it's already there" for a folder but "replace it" for a file.

Moving

  1. Copy and Move: Copy-Item and Move-Item (Novice): Copy-Item makes a copy and leaves the original where it was, Move-Item takes the original to its new place, -Recurse copies a folder with everything in it, and -WhatIf shows exactly where a copy or move would land before anything changes.
  2. Renaming: Rename-Item (Novice): Rename-Item gives a file or folder a new name in the folder it's already in; the new name is only a name, so renaming and moving in one step is Move-Item's job, and Rename-Item never replaces a file that already has the new name.

Many at Once

  1. Wildcards and Filters (Apprentice): The wildcards *, ? and [ ] match many names with one pattern, so one Move-Item carries every photo at once, and Get-ChildItem's -Filter, -Include and -Exclude choose which names to list, -Filter the fastest of the three.

Exercise: Sort the Downloads Folder

  1. Exercise: Sort the Downloads Folder (Apprentice): Sort a messy downloads folder of eighteen made-up files into photos, receipts, school, documents and a backup with New-Item, Copy-Item, Move-Item, Rename-Item and wildcards, and let a Pester check tell you which tasks are done.