Running a simple DOS command in XY script

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
amirvf
Posts: 133
Joined: 18 Oct 2020 00:46

Running a simple DOS command in XY script

Post by amirvf »

I have a directory with 2 text files:

Code: Select all

D:\Test\1.txt
D:\Test\2.txt
In "Command Prompt" I can easily merge the content of the two files with the "copy" command as follows:

Code: Select all

copy D:\Test\1.txt + D:\Test\2.txt D:\Test\merge.txt
In order to run the above DOS command in XY script, I have tried scripting commands: run, runq, runret() with various quotation styles, but most of the times I get the following error:

Code: Select all

The system cannot find the file specified.
Any ideas on how to run the above DOS command in XY script?

highend
Posts: 15016
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Running a simple DOS command in XY script

Post by highend »

A bit more generic (works for a count of selected files >= 2) where the merge.txt is stored in the dst path of the first selected file

Code: Select all

    if (<get CountSelected> >= 2) {
        $selected  = <get SelectedItemsPathNames '" + "'>;
        $dstFile   = gpc(gettoken($selected, 1, '" + "'), "path") . "\merge.txt";
        $arguments = quote($selected) . " " . quote($dstFile);
        end (runret("""cmd"" /c copy /b $arguments", , 65001, 2) != 0), "Joining failed for an unknown reason...";
    }
One of my scripts helped you out? Please donate via Paypal

amirvf
Posts: 133
Joined: 18 Oct 2020 00:46

Re: Running a simple DOS command in XY script

Post by amirvf »

highend wrote: ↑27 Dec 2020 22:09 A bit more generic (works for a count of selected files >= 2) where the merge.txt is stored in the dst path of the first selected file

Code: Select all

    if (<get CountSelected> >= 2) {
        $selected  = <get SelectedItemsPathNames '" + "'>;
        $dstFile   = gpc(gettoken($selected, 1, '" + "'), "path") . "\merge.txt";
        $arguments = quote($selected) . " " . quote($dstFile);
        end (runret("""cmd"" /c copy /b $arguments", , 65001, 2) != 0), "Joining failed for an unknown reason...";
    }
Thanks. It works as expected! :appl:

Post Reply