I've got a directory, C:\temp\test\, containing three DLL's I've called First.dll, Second.dll, Third.dll. I want to create sub-directories named after each of the DLL's.
This is what I've tried so far:
$dirName = "Tenth"
new-item $dirName -ItemType directory
That works. It created a sub-directory called "Tenth".
This also works:
(get-childitem -file).BaseName | select $_
It returns:
First
Second
Third
I've checked the type of the output from that command and it tells me "select $_" is of type System.String.
Now the bit that doesn't work:
(get-childitem -file).BaseName | new-item -Name $_ -ItemType directory
I get the following error repeated three times:
new-item : An item with the specified name C:\temp\test already exists.
At line:1 char:34
+ (get-childitem -file).BaseName | new-item -Name $_ -ItemType directory
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ResourceExists: (C:\temp\test:String) [New-Item], IOException
+ FullyQualifiedErrorId : DirectoryExist,Microsoft.PowerShell.Commands.NewItemCommand
The current folder I'm executing the commands from is C:\temp\test\ .
I haven't been able to find any similar examples on the Internet to show me where I'm going wrong. Can anyone give me any pointers? Cheers.