7

I would like to separate my source code into folders to have a better organization by grouping the files into directories.

In general there are a lot of .h and .cpp files and I usually go separating the folders. I have always used netbeans, but recently I decided to test Visual Studio.

When starting the code (little thing, to follow a tutorial of creation of games in SDL), I began to organize the source in folders. In Visual Studio when I'm working with C ++ I see the option to add filter, to organize the file structure, but I do not see the option to add folders.

I can organize the code in what visually seems to be a folder structure, but when I go to check the files are a mess, it's all mixed up at the root of the program. Menu options only allow me Add a filter:

Apparently it gets organized, but only visually, the codes all remain in the same place.

I would like to know if inside visual studio there is a way to convert these filters into folders, or how to add the folder through visual studio, because I ended up creating the folders and reorganizing manually.

Not that I usually have files with the same name, but in that environment for example this would be impossible. Besides that I think it gets pretty messy if you look for something, or if you need to switch IDE in the future, because I believe that this logical organization will not be reused in another IDE such as Eclipse, Netbeans and etc.

William
  • 131
  • 1
  • 6
  • Possible duplicate of [How to create a folder in Visual Studio C++ 2012](https://stackoverflow.com/questions/12989981/how-to-create-a-folder-in-visual-studio-c-2012) – Robert Andrzejuk Dec 29 '18 at 22:43
  • 1
    For me (where projects have several hundred source files) on way I manage that much code is dividing the project into several libraries. Inside these libraries I subdivide into solution folders. With that said I use `CMake` to generate the project so I don't directly create the solution folders in the IDE. – drescherjm Dec 29 '18 at 22:44
  • Note that even if you have multiple folders, you should ("cannot") have files having the same name and extension. The `.obj`-file created while building your solution will be overwritten by the last file having the same name and you'll get linker-errors (see e.g. [this explanation](https://stackoverflow.com/a/12990389/3757672)). – Markus Nov 13 '21 at 16:09

1 Answers1

1

As you say filters are a purely visual thing, you can organize the files into actual directories using file explorer or when you add a new item to a project you can specify the path where the file will be created. Solution explorer itself does not provide a way to move files on disk.

Note that if you actually use multiple directories you will need to either include part of the path in an #include directive or change the project include search paths so that the file will be found.

SoronelHaetir
  • 14,104
  • 1
  • 12
  • 23