1

I use Hedge to transfer Magic Lantern video files shot on my Canon 5D Mark III.

On OS X, I'm able to use Automator to set up a bash script, to execute an mlv_dump to transfer the files from MLV into cDNG sequences.

The script I use currently is:

cd "$(dirname "$1")"
for f in "$@"; do
    if [[ -f $f ]]; then
        filename=${f##*/};
        folder=${filename%.*}
        mkdir "${folder}";

        ~/mlv_dump --dng $f -o ${folder}/${folder}_;
    fi
done

Can this easily translate into a Windows equivalent?

Thanks,
Thomas

  • 1
    Here's a good place to get started: http://hyperpolyglot.org/shell – mklement0 Jan 28 '18 at 19:28
  • 3
    For any kind of translation work 2 things are required: a) a good understanding of the source language, and b) a good understanding of the target language. If you're lacking that you can either hire someone to do the work for you, or try finding a sucker who does it for free. For the latter SO is not the best of places. – Ansgar Wiechers Jan 28 '18 at 20:36

2 Answers2

5

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)"
  }
}
mklement0
  • 382,024
  • 64
  • 607
  • 775
1

Easy, is a relative answer specific to the skills of the individual, As the others have commented, there is no out of the box thing / tool you can use or buy to do this. It's all manual work, using the pointers and others who have tried to see what you can glean to accomplish you use case.

For example, this, in your block...

    filename=${f##*/};
    folder=${filename%.*}
    mkdir "${folder}";

... is easily translated into...

    $filename='PathToFileName'
    $foldername='PathToFolder'
    mkdir 'FolderName'

Now, that translation is really simplistic, and obviously not complete. That is something you'll have to figure out, using the resources pointed to and the PowerShell built-in help file and those examples.

There are several posts on this very forum on this conversion topic and how others have come to a consensus oh what / if anything can be done.

For example the below will highlight the efforts you'll need to traverse to accomplish X or Y.

Convert simple Bash script to PowerShell?

I am looking to port this bash code to PowerShell. Can anyone shed some PowerShell light on this one?

Convert simple Bash script to PowerShell?

Convert bash script into Windows script

I have the following Unix shell script. I would like to convert this into a Windows .bat file (I know I can use Cygwin instead of adapting it to a Windows environment. But Cygwin is not an option for me).

Convert bash script into Windows script

Convert xargs Bash command to PowerShell?

I've got a simple Bash command to resize some images automatically on a low-traffic website using ImageMagick - I'd like to convert this to a PowerShell command so I don't have to install Cygwin on my webserver.

Convert xargs Bash command to PowerShell?

As noted, there are paid for avenues / even online ones who can potentially be an avenue.

But, you should really read up a bit more on how to do specific things, like..

  • Creating files and folders
  • Accessing/Reading files, importing files, filtering files
  • Loops
  • Operators (comparison and assignment)
  • Navigating the file system/PSDrive
postanote
  • 15,138
  • 2
  • 14
  • 25