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
Printable View
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
A search on MSDN gave this:
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!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.
sorry, I forget to say that I am using C in win32, I am quite sure the file name is right :)
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:
C++-style:Code:int Index = strlen(FileName);
while(Index > 0)
{
if(FileName[Index] == '.')
{
FileName[Index] = '\0';
break;
}
Index--;
}
I'm not sure if that last part is valid. If it isn't, use a temporary string in the assignment.Code:int Index = FileName.rfind('.', 0);
FileName = FileName.substr(0, Index);
Thanks for your great help :)