1
여기 mspaint 폴더에있는 모든 jpg 파일을 저장하는 PowerShell 스크립트가 있습니다. exif thumb을 수정하고 파일 크기를 줄입니다.PowerShell에서 어떻게 시작 프로세스로 문자 경로를 전달합니까?
문제는 경로에 공백이있는 mspaint jpg 파일을 보낼 수 없다는 것입니다. 그렇다면 jpg 파일의 문자 그대로의 경로를 얻기 위해 Start-process를 만드는 방법은 무엇입니까?
$kansio = ($args[0]).replace("'","")
$tiedostot = 0
Write-Host "Folder to process: $kansio" -foregroundcolor White
Get-ChildItem -LiteralPath $kansio | foreach{if($_.Extension -eq ".jpg"){$_.FullName}} |
foreach{
$id = (Start-process mspaint $_ -ea 0 -PassThru).Id
$vikaTallennus = (Get-ChildItem -LiteralPath $_).LastWriteTime
[bool]$onnistui = 0
[void][System.Reflection.Assembly]::LoadWithPartialName("'Microsoft.VisualBasic")
[void][System.Reflection.Assembly]::LoadWithPartialName("'System.Windows.Forms")
do
{
try
{
if((Get-Process -Id $id -ea 'stop').WaitForInputIdle())
{
[Microsoft.VisualBasic.Interaction]::AppActivate($id)
[System.Windows.Forms.SendKeys]::SendWait("^s")
[System.Windows.Forms.SendKeys]::SendWait("{esc}")
for($i=1; $i -le 10; $i++)
{
if((Get-ChildItem -LiteralPath $_).LastWriteTime -gt $vikaTallennus)
{
try
{
Stop-Process -Id $id -force -ea 'stop'
Write-Host "Done: $_" -foregroundcolor Green
$onnistui = 1
break
}
catch
{
#Write-Host "Failed to close the process" -foregroundcolor Red
#Start-Sleep -milliseconds 100
}
}
}
}
}
catch
{
#Write-Host "Failed to catch the process" -foregroundcolor Red
#Start-Sleep -milliseconds 100
}
}
until((Get-Process -Id $id -ea 0) -eq $null -or $id -eq $null)
if($onnistui){$tiedostot++}else{Write-Host "Failed: $_" -foregroundcolor Red}
}
Write-Host "Files saved: $tiedostot" -foregroundcolor Green
감사합니다, 나는 당신의 제안을 약간 수정했습니다 입력해도 : 사용 $ 아이디 = (시작 프로세스 MSPAINT "" "$ _" ""-ea 0 -PassThru) .ID 겠습니까을 필터가 확장자를 확인하는 것보다 빠릅니까? –
예, 파이프 매개 변수를 사용하여 개체를 전달해야하는 필터 매개 변수를 사용하면 속도가 빨라집니다. –