Page 1 of 1

Files selection to command line script

Posted: 04 Feb 2016 11:42
by thecon
Hello!

I have a dos command line program (SetDPI.exe) that manually sets the DPI to PNG files.
Syntax:

SetDPI dpiX dpiY filepattern [filepattern [filepattern...]]

How can I set up a script that:
1) Tests that the files selected really exist
2) wrap double quotes around each file
3) Interactively ask for my wanted DPI. If I give only one input number, then duplicate that number (dpiX dpiY)
4) Check if inputs (space delimited) are numbers (0 up to 1000, decimals permitted, for example 200.34)
5) feed the output list to SetDPI and execute it.
6) pause at the end so that the DOS windows does not disappear.

For example, I want to change the DPI to the following three files which are present to a folder with some other files too:
Test1.png
Test 2.png
test 3.really a png but with a differect extension.txt

I should select those three, use the script which will ask me the desired dpi (for example 300.33) and then execute the following command:
SetDPI 300.33 300.33 "Test1.png" "Test 2.png" "test 3.really a png but with a differect extension.txt"

If I give two numbers (for example 300.33 200.22), then execute the following command:
SetDPI 300.33 200.22 "Test1.png" "Test 2.png" "test 3.really a png but with a differect extension.txt"

Thank you!

Re: Files selection to command line script

Posted: 04 Feb 2016 13:13
by highend
Link to download that setdpi.exe command line version?

Re: Files selection to command line script

Posted: 04 Feb 2016 14:03
by thecon
highend wrote:Link to download that setdpi.exe command line version?
It used to be here:
http://blog.quppa.net/2011/03/10/setdpi-utility/

But not it seems it has disappeard.

Therefore, I am enclosing it from my archive (no responsibilities of course).
SetDPI.Utility.for.PNGs.rar

Re: Files selection to command line script

Posted: 04 Feb 2016 14:25
by highend
Something like this?

You need to adapt the path to your setdpi.exe file...

Code: Select all

    $exe = "R:\SetDPI.exe";

    if !("<selitems>") { status "No files selected, aborted!", "8B4513", "stop"; end 1==1; }
    $input = input("Enter your DPI value(s)...", , "300.33");
    $dpiX = gettoken($input, 1);
    $dpiY = gettoken($input, 2);
    if !($dpiY) { $dpiY = $dpiX; }
    if !(regexmatches($dpiX, "^[0-9.]+$") || regexmatches($dpiY, "^[0-9.]+$")) { status "Wrong DPI values!", "8B4513", "stop"; end 1==1; }

    $content = <<<>>>
@ECHO OFF
"$exe" $dpiX $dpiY <selitems>
ECHO.
ECHO Press any key to continue... & PAUSE >NUL
>>>;
    writefile("%TEMP%\setdpi.bat", $content);
    run "%TEMP%\setdpi.bat", "<curpath>", , 1;

Re: Files selection to command line script

Posted: 04 Feb 2016 15:54
by thecon
highend wrote:Something like this?

You need to adapt the path to your setdpi.exe file...

Code: Select all

    $exe = "R:\SetDPI.exe";

    if !("<selitems>") { status "No files selected, aborted!", "8B4513", "stop"; end 1==1; }
    $input = input("Enter your DPI value(s)...", , "300.33");
    $dpiX = gettoken($input, 1);
    $dpiY = gettoken($input, 2);
    if !($dpiY) { $dpiY = $dpiX; }
    if !(regexmatches($dpiX, "^[0-9.]+$") || regexmatches($dpiY, "^[0-9.]+$")) { status "Wrong DPI values!", "8B4513", "stop"; end 1==1; }

    $content = <<<>>>
@ECHO OFF
"$exe" $dpiX $dpiY <selitems>
ECHO.
ECHO Press any key to continue... & PAUSE >NUL
>>>;
    writefile("%TEMP%\setdpi.bat", $content);
    run "%TEMP%\setdpi.bat", "<curpath>", , 1;
Works, except on files with unicode filenames.
I altered your excellent script so that:

Code: Select all

    $exe = "C:\Boot\SetDPI.exe";
    if !("<selitems>") { status "No files selected, aborted!", "8B4513", "stop"; end 1==1; }
    $input = input("Enter your DPI value(s)...", , "300.125");
    $dpiX = gettoken($input, 1);
    $dpiY = gettoken($input, 2);
    if !($dpiY) { $dpiY = $dpiX; }
    if !(regexmatches($dpiX, "^[0-9.]+$") || regexmatches($dpiY, "^[0-9.]+$")) { status "Wrong DPI values!", "8B4513", "stop"; end 1==1; }
    run "cmd.exe /t:02 /c $exe $dpiX $dpiY <selitems> & echo: & pause", ,0;
Only problem with the code is that if $exe contains spaces, it cannot run.
I tried double or triple quotes around $exe, but it doesn't work. Other than then, it works ok!

Re: Files selection to command line script

Posted: 04 Feb 2016 16:09
by highend
Works, except on files with unicode filenames.
This is not a limitation of XY but your cmd interpreter. Change the codepage to something that can display unicode letters. E.g. in Germany I use chcp 1252 for German "umlauts"...
Only problem with the code is that if $exe contains spaces, it cannot run.
That's the reason why I create a temporary file that is executed instead...

Re: Files selection to command line script

Posted: 04 Feb 2016 16:54
by thecon
Great! Thanks for your help!