Thread: GetFileTitle()

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    173

    GetFileTitle()

    Hi:

    If there is a file named 1234567.bmp, but GetFileTitle() still gives me the file name with extension, what can I do to get the file name 1234567, is there any function made already??Thanks
    Don't laugh at me,I am just a SuperNewbie.

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    A search on MSDN gave this:
    Code:
    MFC Library Reference 	 
    CFileFind::GetFileTitle
    
    Call this member function to get the title of the found file.
    
    virtual CString GetFileTitle( ) const;
    
    Return Value
    
    The title of the file.
    Remarks
    
    You must call FindNextFile at least once before calling GetFileTitle.
    
    GetFileTitle is one of three CFileFind member functions that return some form of the file name. The following list describes the three and how they vary:
    
        * GetFileName returns the file name, including the extension. For example, calling GetFileName to generate a user message about the file c:\myhtml\myfile.txt returns the file name myfile.txt.
        * GetFilePath returns the entire path for the file. For example, calling GetFilePath to generate a user message about the file c:\myhtml\myfile.txt returns the file path c:\myhtml\myfile.txt.
        * GetFileTitle returns the file name, excluding the file extension. For example, calling GetFileTitle to generate a user message about the file c:\myhtml\myfile.txt returns the file title myfile.
    According to this it shouldn't return the extention, so you must be doing something wrong. Is the file name Alpha.txt.txt? Post code!
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  3. #3
    Registered User
    Join Date
    Sep 2001
    Posts
    173
    sorry, I forget to say that I am using C in win32, I am quite sure the file name is right
    Don't laugh at me,I am just a SuperNewbie.

  4. #4
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Manually cut off the end then? If you know the extention has 3-letters, vut off the last 4 characters in the string. To get a little more safe approach, traverse the string from the end until you find a dot, then replace it with the NULL terminator (assuming old C-style strings). Using std::string, you could create a substring of the original one, or use some tokenizer (which I don't know of).

    C-style:
    Code:
    int Index = strlen(FileName);
    while(Index > 0)
    {
      if(FileName[Index] == '.')
      {
        FileName[Index] = '\0';
        break;
      }
      Index--;
    }
    C++-style:
    Code:
    int Index = FileName.rfind('.', 0);
    FileName = FileName.substr(0, Index);
    I'm not sure if that last part is valid. If it isn't, use a temporary string in the assignment.
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  5. #5
    Registered User
    Join Date
    Sep 2001
    Posts
    173
    Thanks for your great help
    Don't laugh at me,I am just a SuperNewbie.

  6. #6
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544

Popular pages Recent additions subscribe to a feed