Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to move folder and its content in powershell

Tags:

powershell

I am trying to move one folder and its content from 1 location to another. Name of the folder is c:\logfiles and it has sub folders and text files, but the script which i have written, it only moves the content of logfiles but i want to move logfiles folder as a whole to a new location

$current_logfiles = 'C:/LogFiles/*'
$new_logfiles = 'C:\My_Project\LogFiles\'

if (!(Test-Path -path $new_logfiles  )) {
New-Item $new_logfiles -type directory

Move-Item  -Path  $current_logfiles  -Destination $ $new_logfiles -Recurse -force

}

like image 406
san Avatar asked Nov 30 '22 18:11

san


1 Answers

It's because you have the *, you're telling it to move everything under C:\LogFiles.

This should work:

$current_logfiles = 'C:\LogFiles'
$new_logfiles = 'C:\My_Project\LogFiles'

if (!(Test-Path -path $new_logfiles)) {
  Move-Item -Path $current_logfiles -Destination $new_logfiles -force
}
like image 200
arco444 Avatar answered Dec 06 '22 10:12

arco444