Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell 如何使用Get ChildItem从文件夹A中选择不在文件夹B中的文件_Powershell_Get Childitem - Fatal编程技术网

Powershell 如何使用Get ChildItem从文件夹A中选择不在文件夹B中的文件

Powershell 如何使用Get ChildItem从文件夹A中选择不在文件夹B中的文件,powershell,get-childitem,Powershell,Get Childitem,我的问题是,如果文件夹A的文件扩展名不同,那么如何打印文件夹B中不存在的文件名 文件夹A中的文件具有.xlsx文件扩展名,文件夹B中的文件具有.txt文件扩展名 以下是一个视觉表示: 文件夹A有3.xlsx文件。 文件夹B有2个.txt文件。 我想要的输出是打印GHI.xlsx文件名,因为它不存在于文件夹B中 以下是我目前的工作: #Get list of files $Files = Get-ChildItem '\C:\My Documents\Folder A\*.xlsm' `

我的问题是,如果文件夹A的文件扩展名不同,那么如何打印文件夹B中不存在的文件名

文件夹A中的文件具有
.xlsx
文件扩展名,文件夹B中的文件具有
.txt
文件扩展名

以下是一个视觉表示:

文件夹A有3.xlsx文件。

文件夹B有2个.txt文件。

我想要的输出是打印
GHI.xlsx
文件名,因为它不存在于文件夹B中

以下是我目前的工作:

#Get list of files
$Files = Get-ChildItem '\C:\My Documents\Folder A\*.xlsm' `
    -Exclude 'C:\My Documents\Folder B\*.txt'

foreach($File in $Files) {
    $Filename = $File.BaseName
    echo  $Filename
}

您可以使用cmdlet筛选
BaseName
属性:


完全没有达到这个要求,我再去喝点咖啡……:)@索达维洛我也经常遇到这种情况;-)@MichelleSantos我更新了我的答案以提高性能,你可以试试这个。谢谢你的接受。@MartinBrandl非常感谢,这肯定会有帮助,因为我要处理很多文件。
$folderA = Get-ChildItem 'C:\My Documents\Folder A' -File
$folderB = Get-ChildItem 'C:\My Documents\Folder B' -File | 
   select -ExpandProperty BaseName)

$folderA | Where-Object BaseName -NotIn $folderB | 
    select -ExpandProperty Name