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!
Files selection to command line script
-
highend
- Posts: 14940
- Joined: 06 Feb 2011 00:33
- Location: Win Server 2022 @100%
Re: Files selection to command line script
Link to download that setdpi.exe command line version?
One of my scripts helped you out? Please donate via Paypal
-
thecon
- Posts: 71
- Joined: 09 Nov 2015 19:08
Re: Files selection to command line script
It used to be here:highend wrote:Link to download that setdpi.exe command line version?
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).
To see the attached files, you need to log into the forum.
-
highend
- Posts: 14940
- Joined: 06 Feb 2011 00:33
- Location: Win Server 2022 @100%
Re: Files selection to command line script
Something like this?
You need to adapt the path to your setdpi.exe file...
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;
One of my scripts helped you out? Please donate via Paypal
-
thecon
- Posts: 71
- Joined: 09 Nov 2015 19:08
Re: Files selection to command line script
Works, except on files with unicode filenames.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;
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;
I tried double or triple quotes around $exe, but it doesn't work. Other than then, it works ok!
-
highend
- Posts: 14940
- Joined: 06 Feb 2011 00:33
- Location: Win Server 2022 @100%
Re: Files selection to command line script
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"...Works, except on files with unicode filenames.
That's the reason why I create a temporary file that is executed instead...Only problem with the code is that if $exe contains spaces, it cannot run.
One of my scripts helped you out? Please donate via Paypal
-
thecon
- Posts: 71
- Joined: 09 Nov 2015 19:08
Re: Files selection to command line script
Great! Thanks for your help!
XYplorer Beta Club