0

I have a directory structure that looks like this :

  • Root
    • Older

I want to parse all folders in root and move them the Older subfolder.

How can I do this?

1 Answer 1

1

You can use get-childitem (gci) to get all childitems of the root-folder ($root), and move them (move-item) to the new destination. You just have to make sure, you will not move the destination itself, therefore we check that.

$root = "C:\temp\root"
$destination = "older"

gci $root | ? {$_.name -ne $destination} | move-item -Destination "C:\temp\root\$destination" -force
Sign up to request clarification or add additional context in comments.

2 Comments

How can I make it fail if the folder exists in the destination?
just cut of the -force Parameter in the move-item Statement and add an -erroraction silentlycontinue to avoid a red error message

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.