Anish Mistry
February 23rd, 2000, 08:48 PM
I have a program that opens a file in binary mode and searches through it to find a string. It works sometimes, but on longer files it just
doesn't seem to read all the data into currentLine. The file that I am reading is a .doc that is about 3 pages of text, and I went
through the debugger and it seemed not to read the first 100 or so charaters in the text part of the file, and the code can't be specific for any
one kind of file, so just reading the .doc header as a case would be out of the question. Any help woould be greatly appreciated. Thanks.
...
// search string is a value read from a file earlier
CStdioFile file;
bool fileIsClosed;
fileHasMoved = false;
if(!file.Open(currentFile.GetFilePath(),CFile::modeRead|CFile::typeBinary))
{// begin error mesage
MessageBox(currentFile.GetFilePath() + " was failed to be opened. Do you have it open if so please close it and archive again.");
fileDest.Close();
currentFile.Close();
return false;
}// end error message
fileIsClosed = false; // file is open
searchString.MakeLower();
CString currentLine;
while(file.ReadString(currentLine) != 0)
{ // begin Get file line
currentLine.MakeLower();
if(currentLine.Find(searchString) != -1)
{ // begin found string in current line
// do stuff when searchString is found in file
} // end found string in current line
} // end get file line
...
Anish Mistry
"The seeds of the future lie buried in the past."
--The Oracle
http://am-productions.8m.com/
amistry@am-productions.8m.com
doesn't seem to read all the data into currentLine. The file that I am reading is a .doc that is about 3 pages of text, and I went
through the debugger and it seemed not to read the first 100 or so charaters in the text part of the file, and the code can't be specific for any
one kind of file, so just reading the .doc header as a case would be out of the question. Any help woould be greatly appreciated. Thanks.
...
// search string is a value read from a file earlier
CStdioFile file;
bool fileIsClosed;
fileHasMoved = false;
if(!file.Open(currentFile.GetFilePath(),CFile::modeRead|CFile::typeBinary))
{// begin error mesage
MessageBox(currentFile.GetFilePath() + " was failed to be opened. Do you have it open if so please close it and archive again.");
fileDest.Close();
currentFile.Close();
return false;
}// end error message
fileIsClosed = false; // file is open
searchString.MakeLower();
CString currentLine;
while(file.ReadString(currentLine) != 0)
{ // begin Get file line
currentLine.MakeLower();
if(currentLine.Find(searchString) != -1)
{ // begin found string in current line
// do stuff when searchString is found in file
} // end found string in current line
} // end get file line
...
Anish Mistry
"The seeds of the future lie buried in the past."
--The Oracle
http://am-productions.8m.com/
amistry@am-productions.8m.com