Sign in to follow this  
Chacha

VC++ Directories Problem

Recommended Posts

I have recently started using Microsoft Visual C++.net 2003 and am confused about project directories. This is the default project directory setup, with my extra 'Data' folder used to store project data such as graphics and sounds:
PROJECT
    main project files...
    DATA
        texture files...
        sound files...
    DEBUG
        app.exe
        other files...
    RELEASE
        app.exe
        other files...


(note that PROJECT, DATA, DEBUG AND RELEASE are all folders)

Ok, this seems nice and simple, but I've found a problem. When specifying directories in my code, such as a directory to a texture file which needs to be loaded, I don't know whether to give the directory relative to the project folder, or relative to the Debug and Release folders. When I run the application inside of the VC++ IDE, the application seems to use directories relative to the main project folder (so in this case I would use directories like "Data/whatever.bmp"). But when I get out of the IDE and run the application on its own, the application seems to use directories relative to where the application actually is (in this case, the application is in the Debug or Release folder), so I would need to specify directories such as "../Data/whatever.bmp". This is very annoying, and I don't know what to do. As an example to prove this problem exists, I wrote a little test program:
int main()
{
    const char *file = "Data/test.txt";
    
    ifstream fin(file);

    if (!fin)
        cout << "File not found!\n";

    else
    {
        cout << "File found!\n";
	fin.close();
    }

    cout << endl;

    system("pause");
    return 0;
}


When I run this app in the actual VC++ environment, the file can be found. But when I go into My Documents and run the app from the 'Release' or 'Debug' folder, the file cannot be found. There must be a way around this, any help is appreciated.

Share this post


Link to post
Share on other sites
Hi,

Well, I think you pretty much figured it out. The resource paths are relative to where you are running the program from - namely, the debug / release folder. However, the IDE makes it look as if you are running the program from the project folder.

Now, I would suggest leaving the paths relative to the project folder, because otherwise, when you are done, you'd have to have in the final application a release folder containing the EXE, and that wouldn't be cool. :)

One way to work around this is simply copy the EXE from the debug / release directory into the project directort after the build, and so if you want to run it from there, you can do it without the IDE. You can also do it automatically.

In the Solution Explorer, right-click your project, then select "Properties". There, choose Build Events -> Post-Build Event. And there, under "Command Line", just type in a command to copy the binary from the build directory into your project directory:

copy $(OutDir)\$(TargetFileName) $(ProjectDir)

An even easier way would be to output your binary straight to the project directory. To make it so, go to project properties again, and then on the "General" page, the very first item - Output Directory - set it to:

$(ProjectDir)

Vovan

Share this post


Link to post
Share on other sites
Yeah, make it output straight to the project directory. That is what I have always done when I would otherwise have this problem. I'll even go out on a limb and say that it would be the preferred way to handle this.

Share this post


Link to post
Share on other sites
Thanks a lot guys.

I have another question. How can I create a new project without VC++ creating a new folder for my project? For example, say I want to create a new project named 'NewProject', and I want it created in an existing directory such as "C:/...blahblah/myprojects", instead of it being created in "C:/...blahblah/myprojects/NewProject".

Share this post


Link to post
Share on other sites
Quote:
Original post by Chacha
Thanks a lot guys.

I have another question. How can I create a new project without VC++ creating a new folder for my project? For example, say I want to create a new project named 'NewProject', and I want it created in an existing directory such as "C:/...blahblah/myprojects", instead of it being created in "C:/...blahblah/myprojects/NewProject".


Easy d00d:

File-->New

Click project tab
select "add to current workspace"
choose your project type
type the project name
erase the "directory" name appended in the box "Location:"

voila.

Share this post


Link to post
Share on other sites
Quote:
Original post by Verg
Easy d00d:

File-->New

Click project tab
select "add to current workspace"
choose your project type
type the project name
erase the "directory" name appended in the box "Location:"

voila.

It doesn't work, there is no "add to current workspace" option (or perhaps I can't find it, but I'm sure that's not the case since I've looked EVERYWHERE). Remember I'm using MSVC++.net 2003.

Please, can somebody help me with this?

Share this post


Link to post
Share on other sites
In the big dialog that lets you choose the project type there are two radio buttons almost at the bottom. The left one's "add to workspace" the right one's "close workspace".

You can choose either, the first will add the new project to the current solution (workspace).


Share this post


Link to post
Share on other sites
Quote:
Original post by Endurion
In the big dialog that lets you choose the project type there are two radio buttons almost at the bottom. The left one's "add to workspace" the right one's "close workspace".

You can choose either, the first will add the new project to the current solution (workspace).

No, I don't mean adding a new project to an existing workspace...what I'm asking is how to create a new workspace without a new folder named 'NewWorkspaceName' being created. Is this even possible?!

[Edited by - Chacha on August 6, 2004 12:44:53 AM]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this