1

Move files up one folder level might seem like a duplicate, but it is not.

Folder Structure

D:.
└───test
    └───Download
        └───First
        └───Second
        └───Third

When I run the following script the Download folder is moved up one level.

Get-ChildItem -Recurse -Filter "Download" | Move-Item -Destination ".\.."

Current Output

D:.
└───test
└───Download
    └───First
    └───Second
    └───Third

But, I want everything inside the Download folder to moved up one level.

Expected Output

D:.
└───test
    └───Download
    └───First
    └───Second
    └───Third

What am I doing wrong?

Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
Ahmad Ismail
  • 11,636
  • 6
  • 52
  • 87
  • what if you hardcode the path of destination – Kahn Kah Jul 24 '18 at 15:54
  • 2
    `Get-ChildItem -Path "Download" | Move-Item -Destination ".\.."` Exactly what this does will depend on your current working directory. – Bacon Bits Jul 24 '18 at 15:55
  • Even though you claim your question is not a duplicate, it absolutely is. You're suffering from the exact same problem (enumerating the *folder* whose content you want to move rather than the *files* and then moving *that folder* instead of its content). And the solution is also very much the same. Please re-read my answer to the other question. – Ansgar Wiechers Jul 24 '18 at 16:00
  • 1
    If you read my answer again you may notice that you were *supposed* to do either `$folder = Get-ChildItem -Recurse -Filter "Download"; Get-ChildItem $folder | % {...}` or `Get-ChildItem "Download\*" | % {...}`. – Ansgar Wiechers Jul 24 '18 at 18:08
  • Does my answer say to use `.\..` as the destination? – Ansgar Wiechers Jul 24 '18 at 23:37
  • **Solution:** `Get-ChildItem -Recurse -Filter "Download" | Get-ChildItem | Move-Item -Destination {$_.Directory.Parent.FullName}` – Ahmad Ismail Jul 25 '18 at 07:41

0 Answers0