Tuesday, December 9, 2025

Moving multiple source Files to a New Path Using PowerShell

 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

# Read file paths from text file $FilePathList = Get-Content ".\pathlist.txt" foreach ($file in $FilePathList) { if (Test-Path -Path $file) { Move-Item -Path $file -Destination "C:\destination\" ` -ErrorAction SilentlyContinue -Force } else { Write-Host "$file does not exist ***" -BackgroundColor Red } }

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.

No comments: