# __FILE__ w/o fullpath

## Recommended Posts

i'm finishing the debuging tool, inspired by the article "uisng xml technologies for enhanced log files", but i'm curious with the __FILE__ macro. in the pictures there, only the filename (CKernel.cpp) was displayed, but when i use the __FILE__ macro the whole path is printed. can you tell me how i can switch between the fullpath and just the filename? i didn't find anything usefull in the msdn...

##### Share on other sites
Evil Steve    2017
As far as I know, the exact value of __FILE__ is defined by the compiler. mmgr always trims the path from the filename when logging the file, and I always do that myself. As far as I know, there is no way to get just the filename.

##### Share on other sites
iNsAn1tY    476
I assume you're using some flavour of Visual Studio. In Debug mode, Visual Studio substitutes the __FILE__ macro for the source file's full path and name. In Release mode, __FILE__ is substituted for just the source file's name. I assume that other IDEs and compilers do the same. If you think about it, it makes sense: a program built in Release mode will probably be running on a completely different machine to the one it was compiled on; including paths with the filenames would be meaningless. In short, the compiler decides what it substitutes for __FILE__, and there's not a damn thing you can do about it [grin].

EDIT: But come to think of it, macros are a pre-processor step, so if you really just wanted the filename, you could send the string substituted for the __FILE__ macro to a function which extracts the filename from a given string: GetFilename(__FILE__). Should be simple enough to code.

##### Share on other sites
If all else fails, you can just extract the needed portion of the file path. Getting the file name from the full path should be nothing more than this code: -

// create the stringstring strPath = "c:\\files\\directory\\file.cpp";string strFName = "";// loop through the string and get the filename from the end of the stringint nSize = strPath.size();for ( int i = nSize - 1; i >= 0; i-- ){    if ( strPath[ i ] == '\\' )        break;    strFName = string( strPath[ i ] ) + strFName;} // end for// do some logging with strPath// ...

There are more than likely much more efficient methods of doing what I just did, but I'm sure you get the idea.

##### Share on other sites
thanks for the replies. isn't there a pre written getfilename function? i'm not shure, but i think there is one, i just don't know wich header i have to include.
i hate the new msdn, it tells me everything about that [...] function, but nothing about the required header file *rolleyes* i also cannot find something 'bout it on the web

btw: i tried the release built, but not all __FILE__ macros are replaced. some are, some are not. i don't understand it...

[Edited by - SiS-Shadowman on March 26, 2006 5:16:07 PM]

##### Share on other sites
Valor Knight    182
I just finished up my logger, and had the same question. The best thing I found was this:
std::string str = __FILE__;int pos = str.find_last_of('\\');str = str.substr(pos+1);

here is the link to the compiler settings, if you can find how to do it in VS 7.1 I would love to here how (I could not find the stupid option)

##### Share on other sites
Endar    668
Quote:
 Original post by SiS-Shadowmani'm finishing the debuging tool, inspired by the article "uisng xml technologies for enhanced log files"

##### Share on other sites
the article is found here:

http://www.gamedev.net/reference/programming/features/xmltech/