Skip to content

Instantly share code, notes, and snippets.

@techthoughts2
Last active October 18, 2017 03:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save techthoughts2/f42a5c82d84b6fc1783089ce3cc5c472 to your computer and use it in GitHub Desktop.
Save techthoughts2/f42a5c82d84b6fc1783089ce3cc5c472 to your computer and use it in GitHub Desktop.
Move files from one directory to a different directory. Then remove the original folder
#gets all origin files and moves them to destination path.
#---------------------------------------------------------
$origPath = 'C:\Users\username\Desktop\images\files'
$destPath = 'C:\destfolder\foldertest'
#---------------------------------------------------------
Write-Output "Moving files..."
Write-Output "From: $origPath"
Write-Output "To: $destPath"
try {
Get-ChildItem -Path $origPath -Recurse -File -ErrorAction Stop | `
Move-Item -Destination $destPath -ErrorAction Stop
Write-Output "File move completed."
Write-Output "Removing original directory."
#removes orignal directory
Remove-Item $origPath
Write-Output "Original directory removed."
}
catch {
Write-Output "An error was encountered:"
Write-Error $_
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment