Sublime Forum

Adding a single file to the project -> how to?

#1

Hi All,

Is there a way to add a single file to the Project (not the whole directory/folder)? How?

Thank you!

0 Likes

#2

Projects in Sublime generally deal with folders and not files, so you would add some number of folders to your project that contain the files that you’re working with.

As such you can’t add a single file to a project per se, but you can fake it to some degree by using folder_include_patterns and file_include_patterns in your sublime-project file’s path entry to constrain what appears, although in this case you will end up with a single folder holding a single file.

For example:

{
	"folders":
	[
		{
			"path": ".",
			"file_include_patterns": ["filename.ext"],
			"folder_include_patterns": ["none"],
		}
	]
}

Here the file_include_patterns includes exactly the file that I’d like to have in my project, so only that file will appear and all other folders will go away. Similarly folder_include_patterns indicates that the only folder we want to see is one called none; since there is no folder by that name, all folders go away and no folders get added, and the result is just a single file inside of the folder.

0 Likes

Adding a folder without childs to the Project
#3

OdatNurd, thanks a lot for your tip!

In case I want to include several files to the project, what’s the correct syntax should be for the file_include_patterns?
Should it be like this:

"file_include_patterns": ["filename1.ext", "filename2.ext"],

or this?

"file_include_patterns": ["filename1.ext"],
"file_include_patterns": ["filename2.ext"],

What’s the way I could indicate the files for several folders?

Should it be like the following?

{
	"folders":
	[
                // FOLDER_1
		{
			"path": ".",
			"file_include_patterns": ["filename1.ext"],
			"folder_include_patterns": ["none"],
		}
                // FOLDER_2
                {
			"path": "../",
			"file_include_patterns": ["filename2.ext"],
			"folder_include_patterns": ["none"],
		}
	]
}

As for the relative path (“path”: “.”), how do you define it? What’s the relative (root) directory/folder?

0 Likes

#4

You want to add multiple items to the list, as in your first example:

"file_include_patterns": ["filename1.ext", "filename2.ext"],

You can also use patterns here, like "*.c" to include all files with a particular extension, etc.

Each entry in the sublime-project file (as in your example) adds a new top level directory, so you would indeed need to have multiple entries if you want to cherry pick certain files from certain places.

A relative path is relative to the location of the sublime-project file. So a folder of "." represents the folder that the sublime-project file is sitting in. The folder can also be absolute if you want to point it at a specific location as well. Remember that if you’re on Windows you need to use \\ or / in the location so that the JSON is valid.

0 Likes