• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 74
  • Last Modified:

Move-Item Powershell

Hey

I would like to move the content of a folder into another folder using powershell.

The content of B into A

C:\Power\A
C:\Power\B\File1.txt (containing the files and folder)

To:

C:\Power\A\File1.txt

(even if A does not exists..)

How to?

Mike
0
mikeydk
Asked:
mikeydk
  • 3
  • 2
2 Solutions
 
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
Something like this?
$src = 'C:\Power\B\file.txt'
$dst = 'C:\Power\A'
if (!(test-path $dst)) { md $dst }
move-item $src $dst

Open in new window

0
 
mikeydkAuthor Commented:
Qlemo...

If I use user example i get:
C:\Power\A\B\file.txt

It have to be C:\Power\A\file.txt

Mike
0
 
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
No, it will not copy the tree, only the file.
0
 
mikeydkAuthor Commented:
$root = "E:\Homedir10"

$users = Get-ChildItem $root

$users | ForEach {robocopy /move $root\$_\Dokumenter $root\$_\Documents -R:0 -W:0}
0
 
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
Your question has been asked clumsy. All you have to do in that case is to rename each user's folder Dokumenter in Documents. Your "solution" is a very costly, unnecessary operation. Just use
Get-ChildItem E:\Homedir10 |
  ? { $_.PsIsContainer } |
  Get-ChildItem -Filter "Dokumenter" | Rename-Item -NewName Documents

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now