While working on powershell I found out that while moving a folder from one location to another, powershell Move-Item command does not create top level folder if the destination folder does not contain any items already.
e.g. if folder A contains only one folder B which has a file MyFile.txt and we want to move folder B inside an empty folder C,
Get-ChildItem "C:\A" |% {Move-Item -Path $_.FullName -Destination "C:\C" -Force}
Above command does not create folder B at the destination location as expected, instead it only moves file the MyFile.txt directly under folder C. A workaround for this issue is just display full name of the folder using $_.FullName like explained below
Get-ChildItem "C:\A" |% {Write-Host $_.Name;Move-Item -Path $_.FullName -Destination "C:\C" -Force}
This command creates a folder B under folder C and moves file MyFile.txt under it.
e.g. if folder A contains only one folder B which has a file MyFile.txt and we want to move folder B inside an empty folder C,
Get-ChildItem "C:\A" |% {Move-Item -Path $_.FullName -Destination "C:\C" -Force}
Above command does not create folder B at the destination location as expected, instead it only moves file the MyFile.txt directly under folder C. A workaround for this issue is just display full name of the folder using $_.FullName like explained below
Get-ChildItem "C:\A" |% {Write-Host $_.Name;Move-Item -Path $_.FullName -Destination "C:\C" -Force}
This command creates a folder B under folder C and moves file MyFile.txt under it.
No comments:
Post a Comment