
📎 This article includes 2 downloadable practice files ↓
“`powershell
$dir = Join-Path $env:TEMP “ps-lesson2”
New-Item -ItemType Directory -Path $dir -Force | Out-Null
Get-ChildItem $dir -Filter *.txt
Get-ChildItem $dir -Filter *.txt | Rename-Item -NewName { $_.Name -replace “report_”, “2026-10_report_” }
Copy-Item “$dir\*.txt” -Destination D:\Backup
Remove-Item $dir -Recurse -Force
“`
-Recurseincludes subfolders;-File/-Directoryfilter types.$_is the current item in the pipeline.-replaceuses regular expressions for renaming patterns.
⚠️ Add -WhatIf to Remove-Item, Move-Item and Rename-Item the first time you run a command. It shows what would happen without changing anything.
More: bulk rename files.
Practice
Run the script (it works in a temp folder and cleans up).
📎 Practice files for this article
- 🖥️ps-02-files.ps1Lesson code file.⬇ PS1 · 462 B
- 📄ps-02-files-output.txtOutput from our test run.⬇ TXT · 102 B
Free to use for learning. Files with macros (.bas) are plain text — import them with Alt+F11 → File → Import File, and always test on a copy.
✨ Ask AI about this article
Stuck on a step? Ask a question and the AI answers using this article.
Free · AI can be wrong