As with any translation between programming languages, there's (a) an as-literal-as-possible approach, which contrasts with (b), an not-immediately-obvious-but-in-the-spirit-of-the-target-language approach.
(b) is always preferable in the long run.
Use PowerShell, because it is the - far superior - successor to the "Command Prompt" (cmd.exe
) and its batch files.
The code below is an attempt at (b), in PowerShell (v3+ syntax).
I encourage you to study the code and post an explanation of it in an answer of your own, so that others may benefit too.
To help with the analysis, consider the following resources:
PowerShell-idiomatic translation of your code:
param(
[Parameter(Mandatory, ValueFromRemainingArguments)]
[System.IO.FileInfo[]] $LiteralPath
)
$outputBaseFolder = Split-Path -Parent $LiteralPath[0].FullName
foreach ($f in $LiteralPath) {
if ($f.exists) {
$outputFolder = Join-Path $outputBaseFolder $f.BaseName
New-Item -ItemType Directory $outputFolder
& "$HOME/mlv_dump" --dng $f.FullName -o "$outputFolder/$($f.BaseName)_"
} else {
Write-Warning "Item doesn't exist or is not a file: $($f.FullName)"
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…