/ Published in: C
Sometimes I want a complete path to a file in the current working directory to make error messages clearer. The URL has alternate approaches.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
// Using MFC. CString cwd; DWORD cwdLen = ::GetCurrentDirectory( MAX_PATH, cwd.GetBufferSetLength(MAX_PATH+1) ); cwd.ReleaseBuffer( cwdLen ); // Note that ReleaseBuffer doesn't need a +1 for the null byte. // Alternate approach, in C, using Win API. static LPCSTR GetDefaultDirectory() { static TCHAR szDirectory[MAX_PATH] = {0}; // place to remember path found. if ( !szDirectory[0] ) // if already found. { ::GetCurrentDirectory(sizeof(szDirectory) - 1, szDirectory); // in winbase.h } return szDirectory; }
URL: http://www.pages.drexel.edu/~mfp27/cppfaqs/