为什么错误消息“(”丢失,而事实并非如此?
Why error message "(" is missing whereas it isn't true?
我不明白为什么 (
不见了?
if not exist ("C:\test") md "C:\test"
At line:1 char:3
+ if not exist ("C:\test") md "C:\test"
+ ~
Missing '(' after 'if' in if statement.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : MissingOpenParenthesisInIfStatement
基于有用的评论:
您正在尝试直接从 PowerShell 使用 cmd.exe
的语法 ,这无法工作(考虑到 PowerShell 根本不同的语法)并导致您看到的解析错误。
使用与您的 cmd.exe
调用等效的 PowerShell,通过 New-Item
:
# Create directory C:\test or use a preexisting directory with that path
# (thanks to -Force).
# A DirectoryInfo object describing the directory is returned,
# which $null = ... discards.
$null = New-Item -Type Directory -Force C:\test
我不明白为什么 (
不见了?
if not exist ("C:\test") md "C:\test"
At line:1 char:3
+ if not exist ("C:\test") md "C:\test"
+ ~
Missing '(' after 'if' in if statement.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : MissingOpenParenthesisInIfStatement
基于有用的评论:
您正在尝试直接从 PowerShell 使用
cmd.exe
的语法 ,这无法工作(考虑到 PowerShell 根本不同的语法)并导致您看到的解析错误。使用与您的
cmd.exe
调用等效的 PowerShell,通过New-Item
:
# Create directory C:\test or use a preexisting directory with that path
# (thanks to -Force).
# A DirectoryInfo object describing the directory is returned,
# which $null = ... discards.
$null = New-Item -Type Directory -Force C:\test