Created
August 26, 2019 15:59
-
-
Save brianvanderlugt/d53847a0d9d45b849f710ed2c8c7045a to your computer and use it in GitHub Desktop.
Moves directories relatively to a new location
This file contains hidden or 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
$directoriesToMove = 'Backup' | |
$newDirectory = 'C:\target\directory' | |
(Get-ChildItem -Recurse -Path $directoriesToMove -Directory) | foreach{ | |
$newPath = $($_.FullName.Replace("$PWD", $newDirectory)); | |
$newPath = $newPath.Substring(0, $newPath.LastIndexOf('\')); | |
New-Item -Path $newPath -ItemType Directory | Out-Null; | |
Move-Item -Path $_.FullName -Destination $newPath} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment