Home > Enterprise >  Escape char in filenamedir under Windows
Escape char in filenamedir under Windows

Time:05-12

I have a really specific issue with Vs Code, which i probably guess has a simple solution but haven't been able to find it.

At some keybind, i get the location of the current file using ${fileDirname} and then send it as text to an ipython terminal for some actions which are irrelevant. The problem is, under windows, the filepath parsed by ${fileDirname}, has the escape slash chars for the subfolders, which causes trouble when trying to use it on ipython (or any other terminal target on windows for the same effect..).

Basically i'm getting a filepath like A:\b\c but i need it like either A:/b/c or A:\\b\\c.

I'm not sure if there is a direct way to just change the output or format of ${fileDirname} with some sort of flag or similar, but any advice would be welcome.

CodePudding user response:

With the extension Command Variable you can transform a text with variables with find/replace and send it to the terminal

  {
    "key": "ctrl i f5",  // or any other combo
    "command": "extension.commandvariable.inTerminal",
    "args": {
      "command": "extension.commandvariable.transform",
      "args": {
        "text": "python ${fileDirname}",
        "find": "\\",
        "flags": "g",
        "replace": "\\\\",
        "addCR": true
      }
    }
  }
  • Related