How to move folder and its content in powershell

san

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

}

arco444

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
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to move folder and its content in powershell

From Dev

How to move content of a folder to current folder?

From Dev

batch move/cut folders and its content to another folder

From Dev

delete a folder and its content

From Dev

Powershell - Monitoring folder Content

From Dev

how can i move the content of a svn folder in another?

From Dev

How to move content of removable drive to folder on the same drive using CMD?

From Dev

How to move a file to a different folder based on user input in powershell

From Dev

How to check if a folder is empty or not and use its content in an if-then-else-statement?

From Dev

Powershell Move Files to a specific folder

From Dev

Route an entire folder and its content

From Dev

Powershell: How to create a file and write its filename in the content

From Dev

How to delete all the folder except one folder and its content using command prompt?

From Dev

How to move a folder into itself?

From Dev

applescript, move folder and its contents to trash

From Dev

How can Powershell copy an entire folder structure but exclude one folder and its contents

From Dev

Powershell GUI how to use a selected Folder and copy its items onto a different folder in another drive

From Dev

Script to move all files starting with the same 7 letters in a different folder named after first 7 chars of its future content

From Dev

How do I move the contents of multiple folders to its root folder using bash?

From Dev

How to move files to a folder while it's known its first letter only through .bat file

From Dev

Powershell: Move files to folder based on Date Created

From Dev

PowerShell Move collection to another folder in SCCM?

From Dev

How to move content of folder to unique folders every three hours in linux platform?

From Java

Android: How to open a specific folder via Intent and show its content in a file browser?

From Dev

Move amount of folders recursive to another folder in the same folder with PowerShell

From Dev

How to search for a folder with PowerShell

From Dev

How to move a pawn to its location

From Dev

How to move branch in SourceTree into Folder?

From Dev

How to move backward parent folder

Related Related

  1. 1

    How to move folder and its content in powershell

  2. 2

    How to move content of a folder to current folder?

  3. 3

    batch move/cut folders and its content to another folder

  4. 4

    delete a folder and its content

  5. 5

    Powershell - Monitoring folder Content

  6. 6

    how can i move the content of a svn folder in another?

  7. 7

    How to move content of removable drive to folder on the same drive using CMD?

  8. 8

    How to move a file to a different folder based on user input in powershell

  9. 9

    How to check if a folder is empty or not and use its content in an if-then-else-statement?

  10. 10

    Powershell Move Files to a specific folder

  11. 11

    Route an entire folder and its content

  12. 12

    Powershell: How to create a file and write its filename in the content

  13. 13

    How to delete all the folder except one folder and its content using command prompt?

  14. 14

    How to move a folder into itself?

  15. 15

    applescript, move folder and its contents to trash

  16. 16

    How can Powershell copy an entire folder structure but exclude one folder and its contents

  17. 17

    Powershell GUI how to use a selected Folder and copy its items onto a different folder in another drive

  18. 18

    Script to move all files starting with the same 7 letters in a different folder named after first 7 chars of its future content

  19. 19

    How do I move the contents of multiple folders to its root folder using bash?

  20. 20

    How to move files to a folder while it's known its first letter only through .bat file

  21. 21

    Powershell: Move files to folder based on Date Created

  22. 22

    PowerShell Move collection to another folder in SCCM?

  23. 23

    How to move content of folder to unique folders every three hours in linux platform?

  24. 24

    Android: How to open a specific folder via Intent and show its content in a file browser?

  25. 25

    Move amount of folders recursive to another folder in the same folder with PowerShell

  26. 26

    How to search for a folder with PowerShell

  27. 27

    How to move a pawn to its location

  28. 28

    How to move branch in SourceTree into Folder?

  29. 29

    How to move backward parent folder

HotTag

Archive