Moving Files to a New Path Using PowerShell
When you need to move a large number of files from different locations into a single directory, managing them manually can be time-consuming. PowerShell makes this task simple with just a few lines of code.
In this example, we store a list of file paths inside a text file (pathlist.txt). PowerShell reads each path and moves the file to a destination folder—while also checking whether the file exists before attempting the move.
PowerShell Script
How it Works
-
Get-Content loads each file path from
pathlist.txt. -
Test-Path confirms whether the file actually exists.
-
Move-Item transfers the file to the destination folder.
-
Errors are suppressed using
-ErrorAction SilentlyContinue. -
Non-existent files are highlighted with a red warning message.
This simple approach helps automate bulk file moves and ensures you’re notified if any paths in your list are invalid.