使用 Powershell 比较具有不同扩展名的文件名
Comparing File Names with different extensions using Powershell
我想比较同一目录中同名但扩展名不同的文件。
示例:一个位置有 6 个文件。
1234.pdf
1234.xml
abcd.pdf
abcd.xml
5678.pdf
efgh.xml
我想将所有 .pdf/.xml 文件与具有相同名称的扩展名为 .xml/.pdf 的文件进行比较,并找出是否有任何 .pdf 或.xml 文件丢失,如上例所示 5678.xml 文件丢失,efgh.pdf 文件丢失。
我试图将所有 .pdf 文件复制到一个文本文件中,并将所有 .xml 文件复制到另一个文本文件中,并尝试比较其中的字符串,但它不起作用。
谁能告诉我如何比较不同扩展名的文件名?
Push-Location "\Cifintgfsfs001\gfs\MXPDFXML\Data\Test"
Get-childitem *.xml | ForEach {
if (!(test-path "$($_.BaseName).pdf")){
"$($_.BaseName).pdf missing"
}
}
Get-childitem *.pdf | ForEach {
if (!(test-path "$($_.BaseName).xml")){
"$($_.BaseName).xml missing"
}
}
Pop-Location
我想比较同一目录中同名但扩展名不同的文件。
示例:一个位置有 6 个文件。
1234.pdf
1234.xml
abcd.pdf
abcd.xml
5678.pdf
efgh.xml
我想将所有 .pdf/.xml 文件与具有相同名称的扩展名为 .xml/.pdf 的文件进行比较,并找出是否有任何 .pdf 或.xml 文件丢失,如上例所示 5678.xml 文件丢失,efgh.pdf 文件丢失。
我试图将所有 .pdf 文件复制到一个文本文件中,并将所有 .xml 文件复制到另一个文本文件中,并尝试比较其中的字符串,但它不起作用。
谁能告诉我如何比较不同扩展名的文件名?
Push-Location "\Cifintgfsfs001\gfs\MXPDFXML\Data\Test"
Get-childitem *.xml | ForEach {
if (!(test-path "$($_.BaseName).pdf")){
"$($_.BaseName).pdf missing"
}
}
Get-childitem *.pdf | ForEach {
if (!(test-path "$($_.BaseName).xml")){
"$($_.BaseName).xml missing"
}
}
Pop-Location