Skip to main content
GameDev.net gamedev.net
🔒 Locked

__FILE__ w/o fullpath

Started by SiS-Shadowman Mar 26, 2006 at 4:28 PM 6 replies 4.3k views
Original Post
SiS-Shadowman
SiS-Shadowman
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...
Evil Steve
Evil Steve
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.
iNsAn1tY
iNsAn1tY
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.
My opinion is a recombination and regurgitation of the opinions of those around me. I bring nothing new to the table, and as such, can be safely ignored.[ Useful things - Firefox | GLee | Boost | DevIL ]
rpg_code_master
rpg_code_master
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.
SiS-Shadowman
SiS-Shadowman
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]
Valor Knight
Valor Knight
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)
There is no life without honor
Endar
Endar
Quote:
Original post by SiS-Shadowman
i'm finishing the debuging tool, inspired by the article "uisng xml technologies for enhanced log files"


I took a look at google but I couldn't find this article, could you post a link?
[size="2"][size=2]Mort, Duke of Sto Helit: NON TIMETIS MESSOR -- Don't Fear The Reaper

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.