However, when I run contig.exe with the same arguments from a DOpus button then the cmd closes after the end of the operation (although @leavedoswindowopen instruction is provided):
<?xml version="1.0"?>
<button backcol="none" display="both" label_pos="right" textcol="none">
<label>Contig</label>
<tip>Show defragmentation of the selected file or directory</tip>
<icon1>#newcommand</icon1>
<function type="batch">
<instruction>@leavedoswindowopen </instruction>
<instruction>@admin</instruction>
<instruction>Contig.exe -a "%1"</instruction>
</function>
</button>
When I ran contig.exe on a directory from the Windows command-line then exactly the files in this directory (and subdirectories) are processed, for example:
contig.exe -v -s -a "D:\DELPHI\PDF"
With the above command-line all the files in D:\DELPHI\PDF are processed
But when I run contig.exe with the same parameters from a DOpus button then all the files in the PARENT directory (!) are processed:
Ah, it's because you are using %1 in an MS-DOS type button. MS-DOS is funny about % characters.
You should use {filepath} instead. %1 is only needed for compatibility with Explorer when defining filetypes and never needs to be used in buttons like this.
(In fact, it doesn't look like %1 works at all in MS-DOS type buttons which is probably just as well as it would conflict with other uses of % in such buttons.)
Thank you, Leo. This works, although quotes should be added to make it work with paths containing spaces:
"{filepath}"
However, there's an other question:
contig.exe seems to process files only when the -s parameter is not used and to process SUB-directories only when the -s parameter is used.
So to be able to process BOTH directories and files with one single DOpus button I would need something like a if-then-else statement inside the button, where the IF command is executed if the selected item is a file an the ELSE command is executed when the selected item is a directory:
IF SelectedItem.IsFile then
contig.exe -v -a "{filepath}"
ELSE IF SelectedItem.IsDirectory then
contig.exe -v -s -a "{filepath}"
Thank you, Leo. The vbs script works, however it does not wait at the end of the processing. Since I'm not fluent in VBS, which command do I need to add to the script to make the output wait for a key-press?
That's what I have done. But the DOpus button and the VBS scripting are two different processes, so when the pause is output (press any key) the scripting output from contig.exe has vanished. That#s why I have asked for a pause statement inside the vbs script command.
Yeah. I assumed cscript at least would make it works but on further investigation it doesn't seem to be easy to make VBScript run commands within the same DOS window as themselves.
The problem is that VBScript doesn't pipe the program's output to the same command window. You can make it do that, but then you get the output in two windows. Seems like a bit of a missing thing in VBScript (or Windows Scripting Host, rather).
BTW, the problem in the root thread turned out to be that @leavedoswindowopen doesn't have any effect if there's a space after it. Turns out the @admin wasn't the problem after all. Should be fixed in the next update.
Thank you, Leo and Steje. I've solved the problem by writing a small utility which does the job very well. For people who would like to use it I've attached it to this posting. For using it in DOpus one could create a button which when clicked with the left mouse button defragments the selected file or the files in the selected directory, and when clicked with the right mouse button only tests the defragmentation of the selected file or the files in the selected directory:
Ah... I gotcha, yeah I don't often have to mess around with output from an external executable needing to show up in my cscript/vb console windows, but I see what you mean.
So then aside from fixes in next releases etc, an "immediate" answer is to use a combo of batch and vbs (and maybe someone more fluent in batch language possibilities has a way to work out the part that we're using VB for in this example...) i.e.:
Change the relevant section of VB of code to (i.e run a batch file instead of the executable):
If fs.FileExists(filepath) Then
command = """contig.cmd"" -v -a """ & filepath & """"
ElseIf fs.FolderExists(filepath) Then
command = """contig.cmd"" -v -s -a """ & filepath & """"
Else
And finally the batch file (contig.cmd):
contig.exe %1 %2 %3 %4
pause
And I suppose that does what the OP is looking for...? The 'folder' case in the CMD file could probably be "technically" cleaner with some SHIFT crap or whatever, since it wouldn't ACTUALLY have a %4 arg... but it "works" even dirty as it is...?
That'll work, but if you run it on multiple selected files or folders then I think you'll get a DOS window for each selected item, instead of one DOS window showing all the results.
Whether that matters depends on how you plan to use the button, of course.
FWIW, its interesting that the effect the extra space has on that particular modifier is actually caused by Opus command editor control adding a 'trailing' space to the end of every argument . Personally, I don't see the need since if there is NO space at the end of a previous argument, Opus also adds a 'leading' space when you add the next argument... Also weird that it always insists on 'visually' adding a newline to the end of every buttons set of instructions (though its not present in the xml for the button). I guess both are an attempt to give the user the next position to continue typing 'stuff' without having to manually hit the spacebar? WOW - Jon, can you turn my coffee pot on in the morning too yet - lol?