1

我正在尝试做一些非常简单的事情,但是由于是 powershell 的新手,我无法找出问题所在:

PS C:\Windows\system32> $directoryMaker = New-Object [System.IO.Directory]::CreateDirectory("C:\test")
New-Object : Cannot find type [[System.IO.Directory]::CreateDirectory]: make sure the assembly containing this type is loaded.
At line:1 char:19
+ $directoryMaker = New-Object [System.IO.Directory]::CreateDirectory("C:\test")
+                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidType: (:) [New-Object], PSArgumentException
    + FullyQualifiedErrorId : TypeNotFound,Microsoft.PowerShell.Commands.NewObjectCommand
4

1 回答 1

2

试试:

$directoryMaker = [System.IO.Directory]::CreateDirectory("C:\test")

在这种情况下,您使用的是静态方法( CreateDirectory(string s)),[System.IO.Directory]那么您不需要实例化[System.IO.Directory]对象来引用此方法本身创建的新文件夹。

于 2013-09-16T12:17:29.573 回答