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
  • 12,350

1 Answers1

1

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
  • 12,350