Last active
October 18, 2017 03:48
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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