Share via


How to set source directory?

Question

Thursday, August 25, 2016 6:24 PM

Currently, all the source files for my project are in the project's top level directory, which makes that directory unnecessarily crowded; since I plan to add more source files, this situation will get only worse.

I would like to move the source files, including headers, to a source code subdirectory but cannot find any way to do so.  Is it possible at this point?  If so, how?

All replies (9)

Thursday, September 8, 2016 3:31 PM âś…Answered

I expect this is not the best solution, but it worked:

(1) Create the source subdirectory and copy (not move) the source files to there.

(2) Remove & delete those files in the Solution Explorer window.

(3) Under Projects (in the tool bar), add an existing item for each of the file in the subdirectory.

Crude, but effective.


Friday, August 26, 2016 8:29 AM

Hi Leigh Janes,

Do you want to category management your source code for your C++ project, is it right?

I create a sample C++ Win32 Console application in my side and then add some code to run it successful. Then I add a subfolder under the project root directory named SubDirectory. And move the Source Files folder and Header Files folder to the SubDirectory directly. The project architecture is shown as below screenshot.

After I change the file directory, I rebuild my project and run it, it still could run successful. So this way would not affect the project running. You could create several sub folders in your project root based on your requirement to manage your project files by category.

Best Regards,
Weiwei

We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.


Friday, August 26, 2016 2:09 PM

This is a bit confusing.

The Solution Explorer window in Visual Studio shows folders for Header File, Resource File and Source Files in spite of the fact that all of the files listed are in the same project directory (X in C:\..\projects\X).

Are you telling me to create my Source subdirectory first, move the files and then what?  Expect Visual Studio to find them???  How do I tell Visual Studio to look in X\Source?


Monday, August 29, 2016 5:41 AM

Hi Leigh Janes,

Yes, if you view these files through the File System, all files are all in the root directory.

But we could manage them in Visual Studio Solution Explorer, where will help us manage these files based on the folder/sub folder that we created. The steps I provided in my first reply, means create the Source SubDirectory in Solution Explorer in Visual Studio.

Best Regards,
Weiwei

We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.


Tuesday, August 30, 2016 2:07 AM

For the third time: HOW do I create the source subdirectory in Solution Explorer???

Should I create the subdirectory in Solution Explorer before creating it in the file system?  Does Solution Explorer create the subdirectory in the file system for me?  What does Solution Explorer do if the subdirectory already exists in the file system?


Tuesday, August 30, 2016 9:35 AM

Hi Leigh Janes,

>> HOW do I create the source subdirectory in Solution Explorer???

Please right-click your project and choose Add -> New Filter -> Create a name for this new filter.

>> Does Solution Explorer create the subdirectory in the file system for me?

No, the Solution Explorer won't create the subdirectory in File System. It just create in Solution Explorer used to filter your files in Solution Explorer.

>> Should I create the subdirectory in Solution Explorer before creating it in the file system?

*      What does Solution Explorer do if the subdirectory already exists in the file system?*

You could create your own subdirectory in file system, but it is not show these exists folder automatically. You need to select your project and click the Show All Files icon on top of the Solution Explorer. After the folder shows in your project, you can add your own files in these folder. But we could not change the default path for the default .h files and .c files when your create the project. Because these files are need stored under the project root. If you change the file path, the project would not find these files when building, which will lead to the project could not run any more.

So I suggest you manage your files in Solution Explorer with adding New Filters.

Best Regards,
Weiwei

We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.


Thursday, September 1, 2016 2:28 PM

I think I understand the following things from your answer.

(1) The changes made in Solution Explorer are for display only.

(2) The only way to get what I want is to start a project from the beginning, and during that process I will be able to tell where I want my source code files to be.

Are those statements correct?


Friday, September 2, 2016 1:46 AM

Hi Leigh Janes,

Yes, according to the default action in current version of C++ project, you need to manage your source file in C++ project through Solution Explorer.

If you have any idea for this default action in Visual Studio, I suggest you submit your idea to Visual Studio User Voice and then share your feedback link here. It can let other communities who has the same requirement to vote and add comments for your feedback.

Best Regards,
Weiwei

We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.


Friday, September 9, 2016 5:40 AM

Hi Leigh Janes,

I'm glad that you find a solution for this issue and thanks for sharing your solution here. Please mark your solution as answer, which is benefit to other communities who has the same issue.

If any questions about Visual Studio IDE, please feel free to come back.

Best Regards,
Weiwei

We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.