我正在使用 PowerShell 的 Add-Content
命令创建文件。然而,当文件夹不存在时,会出现以下错误:
Add-Content : Could not find a part of the path 'C:\tests\test134\logs\test134.log'.
根据文档,这个命令应该会创建文件夹:
PS C:\> Add-Content -Value (Get-Content "test.log") -Path "C:\tests\test134\logs\test134.log"
此命令创建一个新目录和文件,并将现有文件的内容复制到新创建的文件中。该命令使用Add-Content cmdlet添加内容,Value参数的值是一个Get-Content命令,从现有文件Test.log获取内容。path参数的值是运行命令时不存在的路径。在此示例中,只存在C:\ Tests目录,该命令创建其余目录和Test134.log文件。
链接:https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.management/add-content?view=powershell-5.1 似乎是Add-Content中的一个明显问题,你能重现这个问题吗?
编辑:我正在运行PowerShell版本5.1.16299.64
BR Matthias