我如何在与Get-ChildItem结果相同的位置添加文本文件?

问题描述 投票:0回答:1

我正在递归地搜索目录中与特定模式匹配的文件,当我得到匹配时,我想在该特定目录中创建文本文件。

我的目录结构如下:

\fldr1\1\
\fldr1\2\
\fldr1\3\

我当前的代码(powershell v5.1)

Get-ChildItem -Filter "*13000__CLMR*.PDF" -Recurse | foreach {New-Item -Path $_.Parent.FullName -ItemType File -Force -Name "DELETEME.txt"}

返回以下错误:New-Item : Cannot bind argument to parameter 'Path' because it is null.

powershell powershell-5.0
1个回答
0
投票

感谢奥拉夫的答案。有人用

$_.Directory.FullName

而不是

$_.Parent.FullName
© www.soinside.com 2019 - 2024. All rights reserved.