Jump to content
  • Advertisement
Sign in to follow this  
tonyaim83

How to get the path of current working directory

This topic is 3874 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi What is require is to get the path of current working directory.I m working on windows-XP. Is any function avaliable in c/c++ i could find on net #include <unistd.h> char *getcwd(char *buf, size_t size); But not working i don't know why. Can u provide small code of how to use this function or any other function which can do the above task in a better way.

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by j_smith4
Fairly sure that header is only good in Linux. In Windows GetCurrentDirectory() will do what you need. A little Googling says that function is in direct.h, which works in VS6.
At the bottom of the page you linked it says:
Quote:
Header Declared in WinBase.h; include Windows.h.

Share this post


Link to post
Share on other sites
I have used GetCurrentDirectory() like

string Path_value= GetCurrentDirectory();

But it is giving me compilation errors.
1345 C:\Dev-Cpp\include\winbase.h too few arguments to function `DWORD GetCurrentDirectoryA(DWORD, CHAR*)'
What kind of argument it is expecting.

Also i m using Dev-CPP4.9.9.2


Share this post


Link to post
Share on other sites
If you read the article at the link j_smith4 provided, it says that you need to supply two arguments. The first one is the length of the buffer for the current directory string, and the second one is what receives the actual directory string.

Perhaps it'll help if you take a look at this example.

Share this post


Link to post
Share on other sites
Quote:
Original post by mutex
At the bottom of the page you linked it says:
Quote:
Header Declared in WinBase.h; include Windows.h.


It was late and reading it again I didn't word it well. GetCurrentDirectory works fine if you want to use the Windows API, but after I posted I thought maybe he was looking for something thats part of the C libraries instead. And on non Linux getcwd() was moved to direct.h, why they couldn't have just kept unistd.h I don't know.

TCHAR path_value[MAX_PATH];
GetCurrentDirectory(MAX_PATH, path_value);

MAX_PATH is defined in the windows headers as the max length of a valid file name in Windows.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!