【发布时间】:2013-06-24 03:29:27
【问题描述】:
如果文件夹不存在,我正在尝试使用 PowerShell 创建一个文件夹,所以我这样做了:
$DOCDIR = [Environment]::GetFolderPath("MyDocuments")
$TARGETDIR = "$DOCDIR\MatchedLog"
if(!(Test-Path -Path MatchedLog )){
New-Item -ItemType directory -Path $DOCDIR\MatchedLog
}
这给了我文件夹已经存在的错误,它确实存在,但它不应该尝试创建它。
我不确定这里有什么问题
New-Item :具有指定名称 C:\Users\l\Documents\MatchedLog 的项目已经存在。在 C:\Users\l\Documents\Powershell\email.ps1:4 char:13 + 新项目
【问题讨论】:
-
试试这个:New-Item -ItemType Directory -Force -Path C:\Path\That\May\Or\May\Not\Exist
标签: powershell