我正在尝试使用 Remove-Item cmdlet 从变量“$exclude_files”中删除存储为 InputObject 名称的文件列表。
由于它是一个列表,我正在遍历列表并获取 InputObject 文件名。
下面是代码:
$source_dir ="C:\Files"
#Files are in below variable $exclude_files
$exclude_files
InputObject SideIndicator
----------- -------------
Credentials.xml =>
EC2_Ubuntu.pem =>
file2.png =>
file3.txt =>
Terminals.config =>
# tried with giving path and without giving path
foreach ($i in $exclude_files){ Remove-Item -Path $source_dir $i.InputObject }
但是,我收到以下错误:
删除项目:找不到路径“C:\Files\file3.txt”,因为它不存在。在 line:1 char:31 + foreach($i in $exclude_files){Remove-Item $i.InputObject} + ~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~ + CategoryInfo : ObjectNotFound: (C:\Files...file3.txt:String) [Remove-Item], ItemNotFoundException + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.RemoveItemCommand