Reading Folder Names To Create Directories

I am attempting to read all folder names from one directory (that part works) and to create a folder in a different directory with the foldername.  So if C:\Folder1 has a folder named Testing then I want to create the directory R:\CopiedFromC\Testing

I get an error of New-Item : A positional parameter cannot be found that accepts argument '+'. each time my script tries to create the folder.  This is my syntax

$items = Get-ChildItem -Path "C:\Folder1"

foreach ($item in $items)
{
      if ($item.Attributes -eq "Directory")
      {
            New-Item -ItemType directory -Path R:\CopiedFromC\ + $item
      }
}

August 25th, 2015 10:18pm

You can  do this in one line with RoboCopy.

https://www.google.com/?gws_rd=ssl#newwindow=1&q=robocopy+create+folder+structure

Free Windows Admin Tool Kit Click here and download it now
August 25th, 2015 11:35pm

You cannot You cannot add implied strings in PS. Strings must be enclosed in quotes to concatenate with the "add" method.

mystring + joke

this cannot work.

"mystring" + "joke"

this works.

August 25th, 2015 11:40pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics