git mv any folder with it's sub folder to another folder in windows powershell
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
# git mv a folder and sub folders in windows | |
function Move-GitFolder { | |
param ( | |
$target, | |
$destination | |
) | |
if (Test-Path $target -PathType Leaf){ | |
write-output "it's a file ... " | |
git mv $target $destination | |
exit | |
} | |
Get-ChildItem $target -recurse | | |
Where-Object { ! $_.PSIsContainer } | | |
ForEach-Object { | |
$fullTargetFolder = [System.IO.Path]::GetFullPath((Join-Path (Get-Location) $target)) | |
$fullDestinationFolder = [System.IO.Path]::GetFullPath((Join-Path (Get-Location) $destination)) | |
$fileDestination = $_.Directory.FullName.Replace($fullTargetFolder.TrimEnd('\'), $fullDestinationFolder.TrimEnd('\')) | |
New-Item -ItemType Directory -Force -Path $fileDestination | Out-Null | |
$filePath = Join-Path $fileDestination $_.Name | |
git mv $_.FullName $filePath | |
} | |
Remove-Item -Recurse -Force $target | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment