查找文件,无论其扩展名如何

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

我有点卡住了。我正在尝试创建一个脚本,它提取压缩的ISO文件并在模拟器上播放它们。我到目前为止:

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

$7zArgList = @(
    "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"
& $7zPath $7zArgList | 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:\7zPrepper.exe" "C:\Program Files\7-Zip\7z.exe" "C:\Program Files (x86)\PCSX2\pcsx2.exe" "C:\Roms\Game 1.7z"

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

powershell 7zip file-extension file-listing
1个回答
4
投票
$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
© www.soinside.com 2019 - 2024. All rights reserved.