Author Topic: Script for Automatic Multiple instances of cr2hdr (Windows)  (Read 34054 times)

engardeknave

  • Senior
  • ****
  • Posts: 341
Script for Automatic Multiple instances of cr2hdr (Windows)
« on: September 26, 2013, 12:36:15 PM »
Most up to date version is in this post.

Features
-Drag-drop folder onto script, or select from open dialog, or configure static input folder
-Runs multiple instances of Cr2hdr (or virtually anything else with minor editing)
-Easily add exiftool, dcraw, ptlens, etc. commands
-Files are sorted into folders upon completion
-Produces script log, as well as logs for each individual file conversion (broken now)
-Processing is timed

Directions
Copy and paste the code into a .vbs file. Edit the options at the top of the script (most importantly the location of cr2hdr.exe). "Maxprocs" is the number of instances of cr2hdr.exe to run at once.

Make sure all paths end with a "\", ie. "C:\cr2hdr\"

After editing, double click the .vbs file and it will present a dialog to browse for a folder (unless you add an input folder). Select a folder (on your hard drive, not CF) containing the mixed dual ISO .CR2s and plain .CR2s.


Code: [Select]
'------------------------------------------------------------------
'last update: 3/30/2014

cr2hdrpath="C:\cr2hdr\" 'ends with a slash \
cr2hdrexe="cr2hdr.exe"
cr2hdrargs="--compress"

exiftoolpath="C:\exiftool\" 'ends with a slash \
inputfolder="C:\pictures\" 'dialog will start at this folder if set (ends with a slash \)

dualisocr2dir="Dual ISO CR2"
regularcr2dir="Regular CR2"
dngoutputdir="Dual ISO DNG"

organize=true 'sort files into subdirectories when done processing
correcttint=false

maxprocs=4 'Number of simultaneous processes
windowtype=7
'0 Hide the window and activate another window.
'1 Activate and display the window. (restore size and position) Specify this flag when displaying a window for the first time.
'2 Activate & minimize.
'3 Activate & maximize.
'4 Restore. The active window remains active.
'5 Activate & Restore.
'6 Minimize & activate the next top-level window in the Z order.
'7 Minimize. The active window remains active.
'------------------------------------------------------------------

set elog=CreateObject("System.Collections.ArrayList")
elog.add "Started: " & Now()
starttime=Timer

'if inputfolder="" then 'not set in options
  if Wscript.Arguments.Count>0 then
    inputfolder=Wscript.Arguments(0) 'command line
  else
    inputfolder=getfolder("Select the folder containing the dual ISO .CR2 files.")
    if inputfolder="" then WScript.Quit
  end if
'end if

elog.add vbcrlf & "Input folder is " & inputfolder

set fso=CreateObject("Scripting.fileSystemObject")
set mainfolder=fso.GetFolder(inputfolder)
set files=mainfolder.Files
filecount=0
set cr2dngqueue=CreateObject("System.Collections.ArrayList")
set exiftoolqueue=CreateObject("System.Collections.ArrayList")

elog.add vbcrlf & "Searching for .CR2 files"

for Each file in files 'find applicable .cr2s
  if valfname(file.Name,".CR2") then
    cr2dngcmd="""" & cr2hdrpath & cr2hdrexe & """ " & cr2hdrargs & " """ & file.name & """" 'no logs
    'cr2dngcmd="cmd.exe /c """"" & cr2hdrpath & cr2hdrexe & """ " & cr2hdrargs & " """ & file.name & """ > " & file.name & ".log """
    cr2dngqueue.add cr2dngcmd
    elog.add "Queued " & cr2dngcmd
    if correcttint then
      exiftoolcmd=exiftoolpath & "exiftool.exe " & replace(file.name,".CR2",".dng") & " -asshotneutral=""0.473635 1.05 0.624"" -overwrite_original"
      exiftoolqueue.add exiftoolcmd
      elog.add "Queued " & exiftoolcmd
    end if
    filecount=filecount+1
  end if 
next

if filecount=0 then
  elog.add "No files found!"
  msgbox "No files found!"
  dump ""
  WScript.Quit
end if

elog.add vbcrlf & "Converting Dual ISO .CR2 files"
cr2hdrtime=runqueue(cr2dngqueue,maxprocs,cr2hdrexe)

if correcttint then
  runqueue exiftoolqueue,8,"exiftool.exe"
  elog.add vbcrlf & "Running exiftool"
end if

dngcount=0
for Each file in files
  if valfname(file.Name,".dng") then dngcount=dngcount+1
next

if dngcount=0 then
  msg="No DNG files created. Check script options and log."
  elog.add msg
  msgbox msg
  dump ""
  WScript.Quit
end if

if organize then sortfiles

finishline="Processed " & filecount & " file(s). Converted " & dngcount & " Dual ISO(s). Runtime: " & round(Timer - starttime) & " seconds."
elog.add vbcrlf & finishline & vbcrlf

if organize then
  mkdir mainfolder & "\" & "logs"
  dump("\logs")
else
  dump("")
end if

msgbox finishline

setnothing

sub sortfiles()
  elog.add vbcrlf & "Moving Dual ISO .CR2 files"
  set files=mainfolder.Files
  for Each file in files
    if valfname(file.Name,".dng") then 'find .dng but move .cr2 with same file name
      mkdir mainfolder & "\" & dualisocr2dir
      move mainfolder & "\" & fso.GetBaseName(file) & ".CR2", mainfolder & "\" & dualisocr2dir & "\" & fso.GetBaseName(file) & ".CR2"
    end if
  next

  elog.add vbcrlf & "Moving any regular .CR2 files"
  set files=mainfolder.Files
  for Each file in files
    if valfname(file.Name,".CR2") then
      mkdir mainfolder & "\" & regularcr2dir
      move mainfolder & "\" & file.Name, mainfolder & "\" & regularcr2dir & "\" & file.Name
    end if
  next   

  elog.add vbcrlf & "Moving Dual ISO .DNG files"
  set files=mainfolder.Files
  for Each file in files
    if valfname(file.Name,".dng") then
      mkdir mainfolder & "\" & dngoutputdir
      move mainfolder & "\" & file.Name, mainfolder & "\" & dngoutputdir & "\" & file.Name
    end if
  next

  elog.add vbcrlf & "Moving log files"
  set files=mainfolder.Files
  for Each file in files
    if valfname(file.Name,".log") then
      mkdir mainfolder & "\" & "logs"
      move mainfolder & "\" & file.Name, mainfolder & "\" & "logs" & "\" & file.Name
    end if
  next
end sub

function runqueue(queue,instances,exename)
  t=Timer
  Set WshShell=WScript.CreateObject("WScript.Shell")
  WshShell.currentdirectory=inputfolder 'have to set the current directory; can't pass full file path because of how cr2hdr calls adngc
  for Each line in queue
    elog.add "Executing: " & line
    wshshell.run line,windowtype,false
    waitfinish instances,exename
  next
  waitfinish 1,exename
  runqueue=Timer-t 'return elapsed time
  Set WshShell=nothing
end function

sub waitfinish(instances,exename)
  do
    Set myproc=GetObject("Winmgmts:").Execquery("Select * from Win32_Process where name='" & exename & "'")
    if(myproc.count>=instances) then wscript.sleep 100
  loop while myproc.count>=instances
end sub

function getfolder(title)
  MY_COMPUTER = &H11&
  USER_PROFILE = &H28&
  MY_PICTURES = &H27&
  WINDOW_HANDLE = 0
  OPTIONS = &H10&

  Set objShell = CreateObject("Shell.Application")
  Set objFolder = objShell.Namespace(MY_PICTURES)
  Set objFolderItem = objFolder.Self
  if inputfolder<>"" then strpath=inputfolder else strpath=objFolderItem.Path

  Set objShell = CreateObject("Shell.Application")
  Set objFolder = objShell.BrowseForFolder _
    (WINDOW_HANDLE, title, OPTIONS, strPath)
       
  If objFolder Is Nothing Then
      Wscript.Quit
  End If

  Set objFolderItem = objFolder.Self
  getfolder = objFolderItem.Path
end function

sub dump(subfolder)
  dim objfile
  set objFile=fso.CreateTextFile(mainfolder & subfolder & "\dualISOscript.log",True)
  objFile.Write Join(elog.toarray(), chr(13) & chr(10))
  objFile.Close
end sub

sub setnothing()
  set objfile=nothing
  set cr2dngqueue=nothing
  set adngcqueue=nothing
  set deldngqueue=nothing
  set elog=nothing
  set fso=nothing
end sub

function valfname(name,suffix)
  valfname=lcase(Right(name,len(suffix)))=lcase(suffix)
end function

sub mkdir(dir)
  if not fso.FolderExists(dir) then
    fso.createFolder(dir)
    elog.add "Created """ & dir & """"
  end if
end sub

sub move(src,dest)
  elog.add "Moving """ & src & """ to """ & dest & """"
  fso.MoveFile src,dest
end sub

function round(num)
  round=int((num+.005)*100)/100
end function

orim

  • New to the forum
  • *
  • Posts: 22
  • 50D / 70D
Re: Script for Automatic Multiple instances of cr2hdr
« Reply #1 on: September 26, 2013, 01:32:26 PM »
That is supergreen, thank you very much :-)


RenatoPhoto

  • Moderators
  • Hero Member
  • *****
  • Posts: 1509
  • 5DM3 / 7D
Re: Script for Automatic Multiple instances of cr2hdr
« Reply #2 on: September 26, 2013, 01:58:14 PM »
Ok, I am vbs ileterate.

Copied the script to notepad and saved it as file.vbs

Put the directory of my cr2hdr.exe as:

path="F:\0-cr2hdr"

Saved the file.

Double click and ask for the directory for the files, so far it works.

I cannot get it to work with the :
imgprefix="img_"
'imgprefix="DUAL"
imgsuffix=".CR2"

I tried renaming my files to DUALXXXX.CR2
and the script cannot find files.

How should I rename the files?
http://www.pululahuahostal.com  |  EF 300 f/4, EF 100-400 L, EF 180 L, EF-S 10-22, Samyang 14mm, Sigma 28mm EX DG, Sigma 8mm 1:3.5 EX DG, EF 50mm 1:1.8 II, EF 1.4X II, Kenko C-AF 2X

orim

  • New to the forum
  • *
  • Posts: 22
  • 50D / 70D
Re: Script for Automatic Multiple instances of cr2hdr
« Reply #3 on: September 26, 2013, 02:02:16 PM »
U should have it like this, if your prefix is DUAL:

'imgprefix="img_"
imgprefix="DUAL"

RenatoPhoto

  • Moderators
  • Hero Member
  • *****
  • Posts: 1509
  • 5DM3 / 7D
Re: Script for Automatic Multiple instances of cr2hdr
« Reply #4 on: September 26, 2013, 02:09:56 PM »
If I uderstand correctly you are saying that we have two options in the script and by adding the little ' mark infront then we are commenting out that option.

So:

'imgprefix="img_"
imgprefix="DUAL"

means ingnore the prefix: 'imgprefix="img_"
and use the prefix: imgprefix="DUAL"

So I rename my files to:  DUAL__002544.CR2

And the script does not find them?  What am I doing wrong?

http://www.pululahuahostal.com  |  EF 300 f/4, EF 100-400 L, EF 180 L, EF-S 10-22, Samyang 14mm, Sigma 28mm EX DG, Sigma 8mm 1:3.5 EX DG, EF 50mm 1:1.8 II, EF 1.4X II, Kenko C-AF 2X

orim

  • New to the forum
  • *
  • Posts: 22
  • 50D / 70D
Re: Script for Automatic Multiple instances of cr2hdr
« Reply #5 on: September 26, 2013, 02:44:01 PM »
If I uderstand correctly you are saying that we have two options in the script and by adding the little ' mark infront then we are commenting out that option.
So:
'imgprefix="img_"
imgprefix="DUAL"
means ingnore the prefix: 'imgprefix="img_"
and use the prefix: imgprefix="DUAL"
correct

Quote
So I rename my files to:  DUAL__002544.CR2

And the script does not find them?  What am I doing wrong?

I do not fully understand, what R U asking, I am sorry.

In fact, actually I have prefix "_UAL" - like this: _UAL2516.CR2,
so I renamed it at line:
imgprefix="_UAL"
and it worked like a charm.
Try to check your settings. Did you set the right path for cr2hdr.exe at:
path="C:\Users\blah\Documents\cr2hdr" ?

mk11174

  • Hero Member
  • *****
  • Posts: 809
Re: Script for Automatic Multiple instances of cr2hdr
« Reply #6 on: September 26, 2013, 03:54:44 PM »
...so no developers interested in modification of cr2hdr to have manual control instead of automatic detection of fields order? Maybe easier than implementing command line would be 4 versions of cr2hdr, since there is 4 combination of fields order?
I think I made the correct changes from what Alex said, here are the 4 versions plus the normal one. Like always make sure the file is in the same folder as the EXE file when you drag and drop to convert.
https://bitbucket.org/mk11174/magic-lantern/downloads/cr2hdr_combo.zip
500D/T1i  550D/T2i  600D/T3i  700D/T5i

RenatoPhoto

  • Moderators
  • Hero Member
  • *****
  • Posts: 1509
  • 5DM3 / 7D
Re: Script for Automatic Multiple instances of cr2hdr
« Reply #7 on: September 26, 2013, 05:58:26 PM »
Ok, now I got it working.  I must have typed something wrong.

I also changed my path back to :
path="C:\Users\RE\Documents\cr2hdr"

Also I put the latest cr2hdr.exe with the exif.exe and dcraw.exe (http://acoutts.com/a1ex/cr2hdr.zip) in the new directory C:\Users\RE\Documents\cr2hdr


I am using windows 7, and every time the cr2hdr.exe is used I get some security pop up.  Is there a way to disable this security check so that the script runs without my attention..
http://www.pululahuahostal.com  |  EF 300 f/4, EF 100-400 L, EF 180 L, EF-S 10-22, Samyang 14mm, Sigma 28mm EX DG, Sigma 8mm 1:3.5 EX DG, EF 50mm 1:1.8 II, EF 1.4X II, Kenko C-AF 2X

engardeknave

  • Senior
  • ****
  • Posts: 341
Re: Script for Automatic Multiple instances of cr2hdr
« Reply #8 on: September 26, 2013, 06:24:39 PM »
I had that problem too before but it went away by itself. I don't know what I did. I found this though: http://www.sevenforums.com/tutorials/182353-open-file-security-warning-enable-disable.html

RenatoPhoto

  • Moderators
  • Hero Member
  • *****
  • Posts: 1509
  • 5DM3 / 7D
Re: Script for Automatic Multiple instances of cr2hdr
« Reply #9 on: September 26, 2013, 06:38:27 PM »
I am using windows 7, and every time the cr2hdr.exe is used I get some security pop up.  Is there a way to disable this security check so that the script runs without my attention..
For windows 7 64 bit the easy way:  Right click on cr2hdr.exe, select properties, go the bottom of popup and there are two buttons, one is Advanced and the other is a button to unlock this file.
Click Unlock and it will not give the security pop anymore...
This script is now running smooth!
http://www.pululahuahostal.com  |  EF 300 f/4, EF 100-400 L, EF 180 L, EF-S 10-22, Samyang 14mm, Sigma 28mm EX DG, Sigma 8mm 1:3.5 EX DG, EF 50mm 1:1.8 II, EF 1.4X II, Kenko C-AF 2X

orim

  • New to the forum
  • *
  • Posts: 22
  • 50D / 70D
Re: Script for Automatic Multiple instances of cr2hdr
« Reply #10 on: September 28, 2013, 09:29:51 PM »
Hi, engardeknave

it would be nice if your script could delete successfully converted cr2s (only).
Could you add that feature into your script, please?
We really do not need those cr2 files anymore after conversion.

Thank you.

RenatoPhoto

  • Moderators
  • Hero Member
  • *****
  • Posts: 1509
  • 5DM3 / 7D
Re: Script for Automatic Multiple instances of cr2hdr
« Reply #11 on: September 28, 2013, 09:45:36 PM »
Beg to differ....  Maybe an option to do that, I always like to keep the originals.
http://www.pululahuahostal.com  |  EF 300 f/4, EF 100-400 L, EF 180 L, EF-S 10-22, Samyang 14mm, Sigma 28mm EX DG, Sigma 8mm 1:3.5 EX DG, EF 50mm 1:1.8 II, EF 1.4X II, Kenko C-AF 2X

engardeknave

  • Senior
  • ****
  • Posts: 341
Re: Script for Automatic Multiple instances of cr2hdr
« Reply #12 on: September 29, 2013, 09:13:38 AM »
It's a really bad idea to put that much trust in either cr2hdr or the script. There's no way to know every file was converted successfully without manually checking.

blahjovic

  • New to the forum
  • *
  • Posts: 2
Re: Script for Automatic Multiple instances of cr2hdr
« Reply #13 on: October 01, 2013, 01:37:31 AM »
Thanks engardeknave for this.  It's Great!

Is there a way to set the CR2 image path to a folder instead of the dialog box? 

*EDIT*

Never mind, I figured it out.  Just had to read through it..   
For others like me, I changed:

inputfolder=InputBox("Enter the path to the dual ISO shots.","Dual ISO Script")

to

inputfolder="D:\NewPhotos\DUALISO"

engardeknave

  • Senior
  • ****
  • Posts: 341
Re: Script for Automatic Multiple instances of cr2hdr
« Reply #14 on: October 27, 2013, 03:43:18 AM »
Updated to compress DNGs.

Notes:

Install  Adobe DNG Convertor.

Enter the paths for everything at the top. Choose whether or not you want the original DNGs to be deleted (deleteoriginaldng=true/false).

There are a few options for the DNG convertor that can be changed, notably whether or not you want jpg previews. (The previews are not exactly accurate.)

Remember, this will only find and convert .CR2 files.

a1ex

  • Administrator
  • Hero Member
  • *****
  • Posts: 11479
  • 5D Mark Free
Re: Script for Automatic Multiple instances of cr2hdr
« Reply #15 on: October 27, 2013, 07:53:37 AM »
You may want to add these options for the DNG converter: -lossy, -side and -count.
http://feedback.photoshop.com/photoshop_family/topics/dng_converter_what_is_the_command_line_option_for_lossy_compression

Don't use -lossy with dual ISO files.

Marsu42

  • Hero Member
  • *****
  • Posts: 1557
  • 66d + flashes
Re: Script for Automatic Multiple instances of cr2hdr
« Reply #16 on: October 27, 2013, 07:56:04 AM »
There are a few options for the DNG convertor that can be changed, notably whether or not you want jpg previews. (The previews are not exactly accurate.)

The jpeg previews are useless if you are using Lightroom or PS, they are only used by (far in between) 3rd party apps. For the Adobe apps  "-p0 -fl" makes more sense since it embeds "Fast Load Data" which speeds up initial rendering.

Don't use -lossy with dual ISO files.

Ugh? Interesting (I didn't try yet) - why would lossy compression work on converted dual_iso files? Or are you talking of the original cr2, but that's to be processed by cr2hdr before acr?

a1ex

  • Administrator
  • Hero Member
  • *****
  • Posts: 11479
  • 5D Mark Free
Re: Script for Automatic Multiple instances of cr2hdr
« Reply #17 on: October 27, 2013, 09:34:07 AM »
Quote
- Don't use -lossy with dual ISO files.
- Ugh? Interesting (I didn't try yet) - why would lossy compression work on converted dual_iso files?

Here's why:


Marsu42

  • Hero Member
  • *****
  • Posts: 1557
  • 66d + flashes
Re: Script for Automatic Multiple instances of cr2hdr
« Reply #18 on: October 27, 2013, 11:42:53 AM »
Here's why

Edit: After trying to convert some dng to lossy, I see you're correct - but the problems are much more subtle than in your sample, the lossy dng has horizontal stripes which I wouldn't have spotted if I wouldn't have looked closely at 100% crop.

It would be nice to get this fixed if possible, lossy dng is really comfortable to reduce the disk storage of bulk shots (I often use it for focus stack source files) and also for general archival with reduced resolution.

a1ex

  • Administrator
  • Hero Member
  • *****
  • Posts: 11479
  • 5D Mark Free
Re: Script for Automatic Multiple instances of cr2hdr
« Reply #19 on: October 27, 2013, 02:25:16 PM »
I can't see any stripes on the shots I've tried.

FYI, the lossy DNGs are 8-bit. Regular Canon CR2's have 14 bits, from which 3 or more are mostly noise, so the converter is probably optimized for mapping 11 bits into 8 with a nonlinear curve. Dual ISO DNGs have 16 bits, from which 1 or 2 bits are noise; if you apply the same curve used for regular CR2, you lose shadow detail. So, the fix has to be in the DNG converter, not in cr2hdr.

For the same reason, you shouldn't trim the 14-bit raw video data to 10 bits without a LUT. If you only throw away 2 bits it may not be noticeable unless you do extreme color grading, but if you throw 4, you may have surprises.

Danne

  • Hero Member
  • *****
  • Posts: 4268
Re: Script for Automatic Multiple instances of cr2hdr
« Reply #20 on: October 28, 2013, 11:50:53 AM »
IS this working for mac?

Marsu42

  • Hero Member
  • *****
  • Posts: 1557
  • 66d + flashes
Re: Script for Automatic Multiple instances of cr2hdr
« Reply #21 on: October 28, 2013, 12:10:11 PM »
IS this working for mac?

Nope, this script is for Windows (scripting host).

chris_overseas

  • Member
  • ***
  • Posts: 206
Re: Script for Automatic Multiple instances of cr2hdr
« Reply #22 on: October 29, 2013, 04:43:13 PM »
I'd like to propose a new feature - allow any CR2 files that were successfully processed as dual-ISO to be moved out to another directory (same as the compressed DNGs can be). I want this because I typically have all my shots from CF card in one directory (some dual-ISO CR2s, some normal CR2s) and I just want to throw them all at this script and let it sort them out for me. As an end result I want a directory that just contains the DNG/CR2 files that I'll be importing into Lightroom. If the dual-ISO CR2 files stay alongside the non-dual-ISO CR2 files as they currently do then I still have to filter through them manually.

Here's some code to do this. Put this up near the top of the script:

Code: [Select]
dim movecr2s,cr2targetdir
movecr2s=true   'whether to move the original dual-ISO CR2 files to another directory
cr2targetdir="Dual-ISO"   'the subdirectory to move the dual-ISO CR2 files into

...and put this before the   if compressdng then   check:

Code: [Select]
  if movecr2s then
    if not fso.FolderExists(mainfolder & "\" & cr2targetdir) then fso.createFolder(mainfolder & "\" & cr2targetdir)
    ' find any DNG files that were created and move the corresponding CR2 file
    set files=mainfolder.Files
    for Each file in files
      if lcase(left(file.Name, len(imgprefix)))=lcase(imgprefix) and lcase(Right(file.Name, len(imgsuffix)))=lcase(".DNG") then
        fso.MoveFile mainfolder & "\" & fso.GetBaseName(file) & imgsuffix, mainfolder & "\" & cr2targetdir & "\" & fso.GetBaseName(file) & imgsuffix
      end if
    next
  end if

Note that this doesn't run in parallel like the rest of the script but I don't think there'll be any real performance gains from doing so anyway.

The one additional thing that I'd like to see but haven't tried implementing myself yet is to compress the DNG files in place, rather than have them end up in a different directory (so I'd end up with a single directory that I can import directly in to Lightroom).
5D Mark IV 1.0.4 | 5D Mark III v1.2.3 | 16-35mm f4.0L | 24-105mm f4L | 70-200mm f2.8L IS II | 100-400mm f4.5-5.6L II | 800mm f5.6L | 100mm f2.8L macro | Samyang 14mm f/2.8 | 2 x Yongnuo YN500EX

orim

  • New to the forum
  • *
  • Posts: 22
  • 50D / 70D
Re: Script for Automatic Multiple instances of cr2hdr
« Reply #23 on: October 29, 2013, 10:03:28 PM »
chris_overseas

that is the feature which i wanted long time ago,
but could you please edit the script instead of giving a puzzle to us?

As far as I understand your guidance I am getting only:
"Invalid ´for´ loop control variable" code.

chris_overseas

  • Member
  • ***
  • Posts: 206
Re: Script for Automatic Multiple instances of cr2hdr
« Reply #24 on: October 29, 2013, 10:42:31 PM »
that is the feature which i wanted long time ago,
but could you please edit the script instead of giving a puzzle to us?

Sure. I'd intended for engardeknave to incorporate this into the original post hence why I just posted the changes, but here's a whole copy of the modified script for you. Note I haven't tested this exact version since my local version contains a few other changes that you probably won't want and which I quickly stripped out before pasting, hopefully that didn't introduce any problems:

Code: [Select]
'------------------------------------------------------------------
dim cr2hdrpath,cr2hdrexe
cr2hdrpath="E:\Photos\Utils"
cr2hdrexe="cr2hdr.exe"

dim imgprefix,imgsuffix 'used to identify the files we're processing
imgprefix=""
'imgprefix="DUAL"
imgsuffix=".CR2"

dim movecr2s,cr2targetdir 'whether to move the original CR2 files to another directory
movecr2s=true
cr2targetdir="Dual-ISO"

dim adngcpath,adngcexe,compressdng
compressdng=true
deleteoriginaldng=true
adngcpath="C:\Program Files (x86)\Adobe"
adngcexe="Adobe DNG Converter.exe"
adngcoutputdir="Compressed-DNG"

dim maxprocs,windowtype
maxprocs=4
windowtype=7
'0 Hide the window and activate another window.
'1 Activate and display the window. (restore size and position) Specify this flag when displaying a window for the first time.
'2 Activate & minimize.
'3 Activate & maximize.
'4 Restore. The active window remains active.
'5 Activate & Restore.
'6 Minimize & activate the next top-level window in the Z order.
'7 Minimize. The active window remains active.

'------------------------------------------------------------------

dim inputfolder
if Wscript.Arguments.Count>0 then
  inputfolder=Wscript.Arguments(0) 'command line
else
  inputfolder=InputBox("Enter the path to the dual ISO shots.","Dual ISO Script")
  if inputfolder="" then WScript.Quit
end if

dim objShell
set objShell=CreateObject("Wscript.Shell")
objShell.CurrentDirectory=cr2hdrpath 'no idea why it needs this
dim fso
set fso=CreateObject("Scripting.fileSystemObject")
dim mainfolder
set mainfolder=fso.GetFolder(inputfolder)
dim file,files,filecount
set files=mainfolder.Files
filecount=0
dim cr2dngqueue,adngcqueue,deldngqueue
set cr2dngqueue=CreateObject("System.Collections.ArrayList")
set adngcqueue=CreateObject("System.Collections.ArrayList")
set deldngqueue=CreateObject("System.Collections.ArrayList")

'"adobe dng converter.exe" -dng1.4 -cr7.1 -d "C:\test\output" "C:\test\img_9242.dng"

for Each file in files 'find applicable .CR2s
  if lcase(left(file.Name, len(imgprefix)))=lcase(imgprefix) and lcase(Right(file.Name, len(imgsuffix)))=lcase(imgsuffix) then
    cr2dngqueue.add """" & cr2hdrpath & "\" & cr2hdrexe & """ """ & file.Path & """"
    if compressdng then
      adngcqueue.add """" & adngcpath & "\" &  adngcexe & """ -dng1.4 -cr7.1 -d """ & mainfolder & "\" & adngcoutputdir  & """ """ & fso.GetParentFolderName(file) & "\" & fso.GetBaseName(file) & ".DNG"""
      if deleteoriginaldng then deldngqueue.add "cmd.exe /c del """ & fso.GetParentFolderName(file) & "\" & fso.GetBaseName(file) & ".DNG"""
    end if
    filecount=filecount+1
  end if 
next

if filecount=0 then
  msgbox "No files found! Check prefix and suffix."
else
  runqueue cr2dngqueue,maxprocs,cr2hdrexe

  if movecr2s then
    if not fso.FolderExists(mainfolder & "\" & cr2targetdir) then fso.createFolder(mainfolder & "\" & cr2targetdir)
    ' find any DNG files that were created and move the corresponding CR2 file
    set files=mainfolder.Files
    for Each file in files
      if lcase(left(file.Name, len(imgprefix)))=lcase(imgprefix) and lcase(Right(file.Name, len(imgsuffix)))=lcase(".DNG") then
        fso.MoveFile mainfolder & "\" & fso.GetBaseName(file) & imgsuffix, mainfolder & "\" & cr2targetdir & "\" & fso.GetBaseName(file) & imgsuffix
      end if
    next
  end if

  if compressdng then
    if not fso.FolderExists(mainfolder & "\" & adngcoutputdir) then fso.createFolder(mainfolder & "\" & adngcoutputdir)
    runqueue adngcqueue,maxprocs,adngcexe
    if deleteoriginaldng then runqueue deldngqueue,100,"zzzzzzzzzz" 'don't wait for cmd.exe, might be running for another reason
  end if

  msgbox "Finished " & filecount & " files."

end if

set cr2dngqueue=nothing
set adngcqueue=nothing
set deldngqueue=nothing
set fso=nothing
set objShell=nothing
set objfile=nothing
Set WshShell=nothing

sub runqueue(queue,instances,exename)
  dim WshShell,myproc
  Set WshShell=WScript.CreateObject("WScript.Shell")

  dim line
  for Each line in queue
    waitfinish instances, exename
    WshShell.Run line,windowtype,false
  next
 
  waitfinish 1,exename
end sub

sub waitfinish(instances,exename)
  do
    Set myproc=GetObject("Winmgmts:").Execquery("Select * from Win32_Process where name='" & exename & "'")
    if(myproc.count>=instances) then wscript.sleep 100
  loop while myproc.count>=instances
end sub



' The Adobe DNG Converter supports the following command line options:
' -c Output compressed DNG files (default).
' -u Output uncompressed DNG files.
' -l Output linear DNG files.
' -e Embed original raw file inside DNG files.
' -p0 Set JPEG preview size to none.
' -p1 Set JPEG preview size to medium size (default).
' -p2 Set JPEG preview size to full size.
' -cr2.4 Set Camera Raw compatibility to 2.4 and later
' -cr4.1 Set Camera Raw compatibility to 4.1 and later
' -cr4.6 Set Camera Raw compatibility to 4.6 and later
' -cr5.4 Set Camera Raw compatibility to 5 .4 and later
' -dng1.1 Set DNG backward version to 1.1
' -dng1.3 Set DNG backward version to 1.3
' -d <directory> Output converted files to the specified directory. Default is the same directory as the input file.
' -o <filename> Specify the name of the output DNG file. Default is the name of the input file with the extension changed to “.dng”.
5D Mark IV 1.0.4 | 5D Mark III v1.2.3 | 16-35mm f4.0L | 24-105mm f4L | 70-200mm f2.8L IS II | 100-400mm f4.5-5.6L II | 800mm f5.6L | 100mm f2.8L macro | Samyang 14mm f/2.8 | 2 x Yongnuo YN500EX