Manipulating dopus variables

I use Dopus buttons to execute different custom powershell scripts I have written via a button.

The way I execute these are by using the msdos execution with a script like this:
powershell "& Set-FolderImage '{filepath$}' $true"

This works ok, however fails for any file that contains an apostrophe. Is there a way to perform string manipulation on the filepath so that I can replace any apostrophe with a double apostrophe?

I was thinking I could use dos to manipulate the file name, but thought there might be a better solution I was over looking.

Cheers

There's no way to do that, except by calling an intermediate script which changes the way the filepath is quoted.

Also note that, unless you've also added @nofilenamequoting to the command, if there is a space in the filepath then it will have double-quotes (") placed around it automatically.

Nice pick up with the @nofilenamequoting, I will be sure to include that.

I am not having much luck getting the command to work. I read in the doco that that Dopus creates a temp bat file when in MSDos mode. The path to this script can be found by adding echo %0 to script.

The dos command I would need to execute is to escape the string is

Set filePath=c:\mypath.txt Set escapedFilePath=%filePath:'=''% powershell "& write-host '%escapedFilePath%'"
However when I try this in dopus it does not work. Watching the temp folder where the bat file should be created I can that no file is created. Leading me to assume that the dos string replace code is messing with Dopus internal engine for creating the bat file.

This is my test script - It should output the selected file path in the powershell console.

@leavedoswindowopen @nofilenamequoting echo %0 Set filePath={filepath$} Set escapedFilePath=%filePath:'=''% powershell "& write-host '%escapedFilePath%'"
This script however does work, though will fail for any file containing an apostrophe

@leavedoswindowopen @nofilenamequoting echo %0 powershell "& write-host '{filepath$}'"
Any ideas as to why it is not working? Is there a place where this error might be logged?

As a side point I noticed that Dopus does not remove the batch files from the temp folder once execution has finished. Is this a bug?

Cheers

Just as an aside...I've found when I'm writing batch file scripts that do more than just basic things, I sometimes tend to get unexpected results when I use an Opus generated temp batch file in a manner like you're trying to do. So instead I almost always create an external batch file to do what I want, and then I use an Opus button to send the selected files (or active lister path, or whatever you're trying to do) to that batch file.

For me that's much easier. I just write and debug the batch file script first and then I assign that script to an Opus button which uses the appropriate external control code to send what's necessary to the script.

The reason it did not work is due to the Set command.
The first solution I found by trial and error. Once I knew what the cause of the error was I was able to find a possibly better - depending on you scenario - solution via the Dopus forum search.

First solution was to put the string Set in to a variable and use the variable.

@leavedoswindowopen @nofilenamequoting echo %0 @set varSet Set {$varSet} filePath={filepath$} {$varSet} escapedFilePath=%filePath:'=''% powershell "& write-host '%escapedFilePath%'"
The other solution was to use the externalonly only command as described here

@leavedoswindowopen @nofilenamequoting @externalonly echo %0 Set filePath={filepath$} Set escapedFilePath=%filePath:'=''% powershell "& write-host '%escapedFilePath%'"
Both produce the same output batch file. The second solution is no good if you want to run some Dopus internal commands.

Time for a celebratory coffee.

[quote="JohnZeman"]Just as an aside...I've found when I'm writing batch file scripts that do more than just basic things, I sometimes tend to get unexpected results when I use an Opus generated temp batch file in a manner like you're trying to do. So instead I almost always create an external batch file to do what I want, and then I use an Opus button to send the selected files (or active lister path, or whatever you're trying to do) to that batch file.
[/quote]

Thats good advice :thumbsup: . Essentially I'm doing the same thing as you. The main script I'm executing is written in powershell, and the powershell script is being called from dopus. I had some issues in calling the powershell script from dopus when the file name had an apostrophe. I suspect I would have the same issue if I was calling a bat file depending on how the file name had to be passed in.

Cheers mate

For me this simple thing is also working:

@leavedoswindowopen @nofilenamequoting echo %0 powershell "& write-host ""{filepath$}"""

Nice, I didn't even think of trying that. Although a ' and " are not the same, the only issue - though I doubt it would occur - would be if the file path contained a powershell variable name.
Consider this

powershell "& write-host ""c:\$true\""" c:\>c:\True\

Better link, Windows PowerShell 1.0 String Quoting and Escape Sequences

I've read exactly the same on another site when I played around with your Script and following the given advice I came to this line:

powershell '& write-host "{filepath$}"'

...and wondered why it doesn't work. :unamused:
Howsoever, I really don't know anything about Powershell and you've found working solutions for all purposes.
No need to expand this thread to a Powershell-Tutorial. :smiley: