【发布时间】:2022-02-25 15:18:43
【问题描述】:
我有一个目录 C:\temp\test\,其中包含三个我称为 First.dll、Second.dll、Third.dll 的 DLL。我想创建以每个 DLL 命名的子目录。
这是我迄今为止尝试过的:
$dirName = "Tenth"
new-item $dirName -ItemType directory
这行得通。它创建了一个名为“Tenth”的子目录。
这也有效:
(get-childitem -file).BaseName | select $_
返回:
First
Second
Third
我检查了该命令的输出类型,它告诉我“select $_”的类型是 System.String。
现在不起作用的位:
(get-childitem -file).BaseName | new-item -Name $_ -ItemType directory
我得到以下错误重复三遍:
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
我正在执行命令的当前文件夹是C:\temp\test\。
我无法在 Internet 上找到任何类似的示例来告诉我哪里出错了。任何人都可以给我任何指示吗?干杯。
【问题讨论】: