I am trying to move all the files inside a folder to folder which is one step back. Suppose I have three files in vpa_images folder and I want to move those files to VPA_IMAGES file and delete vpa_images folder:
I tried by using:
$new_path=$vpa_images '\vpa_images'
echo $new_path
echo $vpa_images
Move-Item $new_path $vpa_images
I am getting issue as:
D:\RAW\st\Docum\2021-10-12\VPA_IMAGES\vpa_images
D:\RAW\st\Docum\2021-10-12\VPA_IMAGES
Move-Item : Source and destination path must be different.
At D:\powershwll\automationforstaples.ps1:49 char:1
Move-Item $new_path $vpa_images
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
CategoryInfo : WriteError: (D:\RAW\St...AGES\vpa_images:DirectoryInfo) [Move-Item], IOException
FullyQualifiedErrorId : MoveDirectoryItemIOError,Microsoft.PowerShell.Commands.MoveItemCommand
How can take all the files to the VPA_IMAGES folder?
CodePudding user response:
The folder at $new_path
is already located inside $vpa_images
- which is why you receive the error you see.
You'll want:
Get-ChildItem $new_path |Move-Item -Destination $vpa_images
Get-ChildItem
will enumerate the files/folders inside $new_path
and Move-Item
then moves each of them to $vpa_images