Search code examples
regexvisual-studio-codetransform

VSCode snippet transform to determine the containing directory


I've been unable to determine the transform to use to grab the directory that a new file is in from the TM_DIRECTORY that VSCode exposes?

i.e. For a path like c:\a\b\c\d\e I would like to get e as the output. I also have linux co-works so it should also work for something like /mnt/a/b/c/d/e


Solution

  • Try this snippet:

    "stripLastDirectory": {
        "prefix": "lsd",
        "body": [
          "${TM_DIRECTORY/.*[\\\\|\\/]+(.*)/$1/}"
        ],
    },
    

    I am unable to test that on Linux but it should work on all OS's.