Thread: How can I change the value of __FILE__?

  1. #1
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545

    How can I change the value of __FILE__?

    Hi,
    Currently (using VC++ 6.0) when I print out __FILE__ I get something like:
    Code:
    C:\blah\blah\blah\file.cpp
    but I'd like it to display a relative file path which starts below the first directory:
    Code:
    \blah\blah\file.cpp
    Is that possible in VC++ 6.0? If so, how?

  2. #2
    Internet Superhero
    Join Date
    Sep 2006
    Location
    Denmark
    Posts
    964
    Quote Originally Posted by cpjust View Post
    Hi,
    Currently (using VC++ 6.0) when I print out __FILE__ I get something like:
    Code:
    C:\blah\blah\blah\file.cpp
    but I'd like it to display a relative file path which starts below the first directory:
    Code:
    \blah\blah\file.cpp
    Is that possible in VC++ 6.0? If so, how?
    Couldn't you just save the output from __FILE__ into a string and then backtrack through the string until you encounter the third backslash, then just throw away the rest?
    How I need a drink, alcoholic in nature, after the heavy lectures involving quantum mechanics.

  3. #3
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  4. #4
    Registered User
    Join Date
    Dec 2006
    Location
    Scranton, Pa
    Posts
    252
    Yea, I'd say the chop suggested above would do;

    Code:
     //string getDrivePath {C:\blah\blah\blah\file.cpp}
     string::size_type loc= getDrivePath.find_first_of("\\");
     getDrivePath.erase(loc-1);

  5. #5
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Quote Originally Posted by Neo1 View Post
    Couldn't you just save the output from __FILE__ into a string and then backtrack through the string until you encounter the third backslash, then just throw away the rest?
    That would make for a much less elegant solution and would require knowledge of the relative path position of each .cpp file so I would know where to chop it off.
    When I pull the files out of Visual Source Safe, I might put them into C:\VSS_root\ but someone else might put them into Z:\SomeStupidName\VSS\Root\

    Quote Originally Posted by Dave_Sinkula View Post
    I see absolute paths when I look at the properties for each file in File View (although I'm not sure why since every developer has their own VSS root directory on their machine). I'm guessing that's what I should turn into relative paths?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. type casting?
    By greatonesv in forum C Programming
    Replies: 12
    Last Post: 10-22-2008, 08:21 PM
  2. c++builder6 change form names problem
    By Leite33 in forum C++ Programming
    Replies: 2
    Last Post: 06-09-2008, 08:20 AM
  3. Change Value in an array
    By beginner999 in forum C Programming
    Replies: 3
    Last Post: 01-18-2003, 07:16 AM
  4. Replies: 2
    Last Post: 11-08-2002, 03:22 AM
  5. Replies: 2
    Last Post: 09-04-2001, 02:12 PM