查找文件而不考虑其扩展名

Find a file regardless of its extension

我有点卡住了。我正在尝试创建一个脚本来提取压缩的 ISO 文件并在模拟器上播放它们。我已经走到这一步了:

param (    
    [string]zPath, # File location of 7z
    [string]$emulatorPath, # File location of the Emulator exe
    [string]$filePath # File location of the compressed file
)

zArgList = @(
    "e", # 7z arguments go here
    $filePath
)

# Location of the decompressed game <<< This is what is incorrect!!!
$decompressedFile = $filePath.Substring(0, $filePath.LastIndexOf("."))

# Start 7z and print the output in the console
"Starting decompression using 7z"
& zPath zArgList | Out-Host

# Start Emulator
"Starting Emulator"
Start-Process $emulatorPath -ArgumentList """$decompressedFile""" -Wait

# Remove the decompressed file when Emulator closes
"Removing the decompressed file"
Remove-Item $decompressedFile

"Done"

因此我开始游戏的命令(将此 .ps1 转换为 .exe 后)将类似于:

"ThisCode.exe" "7zip.exe" "Emulator.exe" "Path2Rom"

例如

"C:zPrepper.exe" "C:\Program Files-Zipz.exe" "C:\Program Files (x86)\PCSX2\pcsx2.exe" "C:\Roms\Game 1.7z"

我已经确定了我需要修改我的脚本的位置,以使其在正确的位置查找我提取的文件...未压缩文件的文件名始终与存档文件名相同,除了扩展名为 . ISO 或 .BIN 扩展名。理想情况下,我希望脚本首先检查 .ISO,如果未找到,则检查 .BIN,但我们已经超出了我的知识水平...非常感谢任何帮助!

$filepath_without_ext = [System.IO.Path]::ChangeExtension($filepath,$null)
# or
$filepath_without_ext = $filePath.Substring(0, $filePath.LastIndexOf("."))

$decompressedFile = Get-Item -Path "$filepath_without_ext*" | Where-Object -Property Extension -Match -Value 'BIN|ISO' | Select-Object -Last 1 -ExpandProperty FullName