Turn {sourcepath$} into python forward slashes

I want to use the{sourcepath$} in some buttons, but it requires the path to be in Python forward slashes. Is there a way to do this?

If you use scripting you can search and replace the slash characters. I don't think there's a way without scripting.

On Windows all paths handling, both built-in and object oriented (pathlib), should work in the same way with both slashes and backslashes. This is not exactly true only in edge cases like \\?\ or \\UNC\ prefixes.

I am trying to set a button that will allow me to point to a folder (I use Calibre Ebook Manager) and have the Calibredb run the catalog command for it. As it is now, I have to create each catalog location individually, which is ok for my main, non-moving libraries, but I wanted to be able to point it to other catalogs and not have to manually type in the following:

calibredb.exe catalog "C:/Users/Robin/Documents/CalCat 0.ALL.csv" --with-library="C:/Users/Robin/Main Calibre/0.All"

I want to put a source path for the parts that indicate a specific folder - a source path for the catalog name and location. The catalog name just needs to be the folder name but the source path to the library needs to be in the location.

Any suggestions?

I have no idea how to script, I just found this in the Calibre manual, it's to be used in the command.exe and I just gerry-rigged it into a button.

With this command (which is in a button) I don't even have to point to the folder, I just click the button since the source is already set. What I end up with is a full catalog deliverd to my Documents folder named "CalCat 0.All" and it is the full database information for the Calibre Library 0.All.

I have an "edit for use" button that I just manually copy over with the current info, but those forward slashes just can't be copied when I right click, copy full file path.

Have you tried it using normal backslashes? It'd be really unusual for someone to make a Windows .exe file and then have it not understand paths with backslashes. So unusual that I would complain to them. :slight_smile:

Something like this will convert the current path to using forward slashes, and insert it into a command to be run. (Your example has two paths, so I'm not sure if this is exactly what you want, but the rest should be easy.)

function OnClick(clickData)
	var cmd = clickData.func.command;
	var path = new String(DOpus.FSUtil.Resolve(clickData.func.sourcetab.path));
	path = path.replace(/\\/g,'/');

	var cmdLine = 'calibredb.exe catalog "' + path + '/Documents/CalCat 0.ALL.csv" --with-library="' + path + '/Main Calibre/0.All"';

//	cmd.RunCommand(cmdLine);

That will output what it would run to the script log (or Button Editor output panel if you run it from there, which is what I'd recommend to save time).

If it looks right, comment out the DOpus.Output line near the bottom, and un-comment the cmd.RunCommand line below that, to make it actually run the command.

Yes it would be nice to have a built in feature for this that could be assigned to a keyboard shortcut...

I use this a lot as well for R, and will have a look at the script Leo provided to see how that works for me.

I also just found out that the alpha version of VoidTools Everything 1.5 does have a configurable option for this.