Suppress Binary files in VS Code File Explorer

Viewed 1253

I have my C++ folder which have all the C++ codes and their corresponding binary files. I have been looking around to find a way to hide them from the explorer view of VS Code but could not find a suitable pattern as they have no extension.

I tried this in the settings.json file, but it hides everything in the folder.

    "files.exclude": {
                  "**/*": true,
                  "**/*.cpp": false
}

Then I tried this, but it hides both the files.

"files.exclude": { 
        "**/*" :{ "when": "$(basename).cpp" }     
    }

So I tried this, but it hides the binary files and not the c++ files.

"files.exclude": { 
        "**/*.cpp" :{ "when": "$(basename)" }     
    } 

So I thought swapping the two terms might work.

"files.exclude": { 
        "**/$(basename)" :{ "when": "$(basename).cpp" }     
    }

But it doesn't work. If anyone can suggest something.

2 Answers
"files.exclude": {
              "**/*": true,
              "**/*.cpp": false }

From what I have gathered from this, you want everything out of your way except for the CPP source files. Here is what you can do:

"files.exclude": {
     "**/*.{[^.cpp]}*": true
}

What you are trying to do is

  • hide all files

  • then show CPP files.

This does not work. Because, after the first statement there is nothing on the File Explorer list, so your second statement has no effect. What I did is that I joined this two logical statements in one glob so that it basically becomes "Exclude everything but not the CPP files"

Well I couldn't find a way to hide only binary files, but I found a workaround:

I edited my tasks.json to save the binary file with .o extension and changed launch.json to open same, then I excluded the .o extension

Added ".o" at this line in my launch.json

            "program": "${fileDirname}/${fileBasenameNoExtension}.o",

Added ".o" here in my tasks.json

 "args": [
            "-g",
            "${file}",
            "-o",
            "${fileDirname}/${fileBasenameNoExtension}.o",]

Finally changed settings

 "files.exclude": {
    "**/*.o": true
},

The binary works the same way.

OPTIONAL:

Additionally, if you use code-runner, you will have to add .o in the cpp of

"code-runner.executorMap":

setting

Related