3

I am flattening a directory and I want to move items that are directories, but leave files untouched.

Unfortunately, there is no distinct pattern that can be wildcard matched between the directories and the files. I want to know if it is possible to tell Move-Item to only examine directories (or on the flip side files).

Examining the output of Get-Help -Name Move-Item this does not seem to be directly possible (i.e. by a parameter like -ItemType). Of the top of my head it might be possible to do this using a hack, e.g. -Exclude *.*, but I want a more robust solution. Thanks.

Destroy666
  • 5,299
  • 7
  • 16
  • 35
  • 1
    Could [this answer](https://stackoverflow.com/a/68326645/21885072) be helpful? – oxou Aug 03 '23 at 00:03
  • 1
    Possibly. I had wanted a simple one liner, but I guess a `ForEach` loop with a condition would achieve what I was after. Thanks. – Jordan Dennis Aug 03 '23 at 00:07

1 Answers1

2

You shouldn't look at just the function itself, remember PowerShell has powerful piping capability. To move only directories, filter them first, then pipe into Move-Item, e.g.:

Get-ChildItem -Path C:\Some\Dir -Directory | Move-Item -Destination C:\Other\Dir

-Directory switch of Get-ChildItem means that only folder children will be found.

Destroy666
  • 5,299
  • 7
  • 16
  • 35