File handling issue
-
CFileStdio saptxt; saptxt.Open("**temp_170807.txt**",CFile::modeRead);
In the above case the file temp_170807 has to be located in the same folder as the application. How can i change it to something like "C:\My folder\temp_170807.txt"?? Also how can i make this text-file name generic ie. like "temp_*.txt"?? I m using VC++ MFC application -
CFileStdio saptxt; saptxt.Open("**temp_170807.txt**",CFile::modeRead);
In the above case the file temp_170807 has to be located in the same folder as the application. How can i change it to something like "C:\My folder\temp_170807.txt"?? Also how can i make this text-file name generic ie. like "temp_*.txt"?? I m using VC++ MFC applicationIsn't it CStdioFile?? And you can just include the path also with the file name. saptxt.Open("C:\\My Folder\\temp.txt",CFile::modeRead); But you can’t open a bunch of files using *, if that’s what you meant by generic file name.
"What's on your mind, if you will allow the overstatement?"
-
CFileStdio saptxt; saptxt.Open("**temp_170807.txt**",CFile::modeRead);
In the above case the file temp_170807 has to be located in the same folder as the application. How can i change it to something like "C:\My folder\temp_170807.txt"?? Also how can i make this text-file name generic ie. like "temp_*.txt"?? I m using VC++ MFC applicationyashveer wrote:
In the above case the file temp_170807 has to be located in the same folder as the application. How can i change it to something like "C:\My folder\temp_170807.txt"??
Err,
saptxt.Open("C:\My folder\temp_170807.txt",CFile::modeRead);
or am I missing something here? -
yashveer wrote:
In the above case the file temp_170807 has to be located in the same folder as the application. How can i change it to something like "C:\My folder\temp_170807.txt"??
Err,
saptxt.Open("C:\My folder\temp_170807.txt",CFile::modeRead);
or am I missing something here? -
CFileStdio saptxt; saptxt.Open("**temp_170807.txt**",CFile::modeRead);
In the above case the file temp_170807 has to be located in the same folder as the application. How can i change it to something like "C:\My folder\temp_170807.txt"?? Also how can i make this text-file name generic ie. like "temp_*.txt"?? I m using VC++ MFC application -
hi, please mention the complete error... also,change the line to saptext.Open("C:\\My folder\\temp_170807.txt",CFile::modeRead); note the slashes...
swaroop
hi swaroop double back-slash solved that problem... In the location C:\Myfolder i could have, lets say: temp_170807.txt temp_180807.txt, etc.... But only one file at a time will be present so i need to give a generic criteria like: C:\\My folder\\temp_*.txt Hope you got the problem
-
Well thanks Swathee i was putting single back-slash"\" double back-slash solved the problem...thnks[:)] but the problem of temp_*.txt still remains what can i do to get rid of this problem?? Program doesnt take temp_*.txt
-
What are you trying to do exactly?? you have to open files separately you can't open them in a bunch.
"What's on your mind, if you will allow the overstatement?"
-
hi swaroop double back-slash solved that problem... In the location C:\Myfolder i could have, lets say: temp_170807.txt temp_180807.txt, etc.... But only one file at a time will be present so i need to give a generic criteria like: C:\\My folder\\temp_*.txt Hope you got the problem
-
better u don use the multiple selection like this, use a CFileDialog class for that purpose, refer MSDN
swaroop
actullay by giving * wont solve ur problem, os else wat u can do is , if the file name ends with constant increase like temp_001, temp_002, etc just put the file open in a loop , concat the file name with the count (eg001,002) and open it and use it, don forget to close before u leave the loop:)
swaroop
-
i m opening only one file at a time.... only one file at any given time will be present in the folder: C:\\My folder\\ i.e. i have either text_1000.txt or text_1001.txt in that location so i need to give something like text_*.txt i hope its clear...
I guess you will have to find the file name at runtime and then read it?!! There is a class called CFileFind MFC, you can use that,
CFileFind finder; finder.FindFile("C:\\Design Docs\\temp*.txt"); // this will find your file finder.FindNextFile(); // it is compulsory to call this function before you call GetFilePath CString filename = finder.GetFilePath(); // this will get the file name along with the path, so you can use this to open the file and read. finder.Close();
Hope this solves your problem. Happy weekend."What's on your mind, if you will allow the overstatement?"
-
I guess you will have to find the file name at runtime and then read it?!! There is a class called CFileFind MFC, you can use that,
CFileFind finder; finder.FindFile("C:\\Design Docs\\temp*.txt"); // this will find your file finder.FindNextFile(); // it is compulsory to call this function before you call GetFilePath CString filename = finder.GetFilePath(); // this will get the file name along with the path, so you can use this to open the file and read. finder.Close();
Hope this solves your problem. Happy weekend."What's on your mind, if you will allow the overstatement?"
-
CFileStdio saptxt; saptxt.Open("**temp_170807.txt**",CFile::modeRead);
In the above case the file temp_170807 has to be located in the same folder as the application. How can i change it to something like "C:\My folder\temp_170807.txt"?? Also how can i make this text-file name generic ie. like "temp_*.txt"?? I m using VC++ MFC applicationI suggest studying up on the concept of absolute vs. relative paths.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne