|
|
Dear All,
I am developing an application in MFC VC++ Version 6.0 for Windows 2000.
I want to check existence of a file in my application eg. i want to check whether c:\rohit\abc.txt exists of not
Can any body please tell me the API for this ?
Feel free to ask any further queries in this regards,
Thanks
Rohit Dhamija
|
|
|
|
|
You can do it via FindFirstFile
Specify in the first parameter file name you need to verify
You will get as result INVALID_HANDLE_VALUE if file does not exist
Otherwise, you will get a valid handle & you must close it with FindClose function
|
|
|
|
|
Thanks max,
That was very useful. i got the following sample code from msdn . And it solved my problem too!
define _WIN32_WINNT 0x0400
#include "windows.h"
int
main(int argc, char *argv[])
{
WIN32_FIND_DATA FindFileData;
HANDLE hFind;
printf ("Target file is %s.\n", argv[1]);
hFind = FindFirstFile(argv[1], &FindFileData);
if (hFind == INVALID_HANDLE_VALUE) {
printf ("Invalid File Handle. Get Last Error reports %d\n", GetLastError ());
} else {
printf ("The first file found is %s\n", FindFileData.cFileName);
FindClose(hFind);
}
return (0);
}
|
|
|
|
|
if(0xFFFFFFFF !=GetFileAttributes(filename))
/*file exists*/
else
/*does not*/
Hari Krishnan
|
|
|
|
|
if (_access("c:\\rohit\\abc.txt", 00) == 0)
{
// file exists
}
HPS HwndSpy - GUI developer's aid to visually
locate and inspect windows. For the month of August
only, use coupon code CP-81239 for 30% off.
|
|
|
|
|
You can use PathFileExists(...) from the shell api
if( PathFileExists( strPath ) )
{
}
|
|
|
|
|
_access()
GetFileAttributes()
CFile::GetStatus()
|
|
|
|
|
hi,
i would like to learn about data recovery / undelete.
can anyone please give me links or source code ?
Thanx.
Hari Krishnan
|
|
|
|
|
|
I had read about a utility which retrieves files deleted by Shift+Del...
I think it was one of Norton's utilities.
The theory used there was that when files are deleted by the user, they don't actually go off the disk right away but the sections of the disk are marked as deleted. The utility read through these sections and retrieves the data.
Just wondering if (hoping that) you might have any additional info.
"It was when I found out I could make mistakes that I knew I was on to something."
-Ornette Coleman
|
|
|
|
|
Other than the one link no. I beleive that is what the source does from the link however.
John
|
|
|
|
|
Where is there an accessible copy of the MFC FAQ ?
I was trying to point someone to it yesterday and I could not find it online either at Code Project or externally.
|
|
|
|
|
|
Wow, last update was 1998!!! Anything more recent?
Thanks though
|
|
|
|
|
There is some more recent stuff here.
HPS HwndSpy - GUI developer's aid to visually
locate and inspect windows. For the month of August
only, use coupon code CP-81239 for 30% off.
|
|
|
|
|
I am writing a class for serial port communication.
It always returns FALSE when I set commport state by calling
win32 api SetCommState.
following is some code from my class:
//code starts here
//m_hComm is an effective handle to commport
m_dcb.DCBlength= sizeof(DCB);
m_dcb.BaudRate =nBaud;
m_dcb.ByteSize = nDataBits;
m_dcb.Parity =nParity ;
m_dcb.StopBits =nStopBits;
m_dcb.fBinary=TRUE;
m_dcb.fDsrSensitivity=FALSE;
m_dcb.fParity=bParity;
m_dcb.fOutX=FALSE;
m_dcb.fInX=FALSE;
m_dcb.fNull=FALSE;
m_dcb.fAbortOnError=TRUE;
m_dcb.fOutxCtsFlow=FALSE;
m_dcb.fOutxDsrFlow=FALSE;
m_dcb.fDtrControl=DTR_CONTROL_DISABLE;
m_dcb.fDsrSensitivity=FALSE;
m_dcb.fRtsControl=RTS_CONTROL_DISABLE;
m_dcb.fOutxCtsFlow=FALSE;
m_dcb.fOutxCtsFlow=FALSE;
BOOL bRet= ::SetCommState(m_hComm, &m_dcb);
if(!bRet)
{
CloseHandle(m_hComm);
MessageBox(NULL, "Set comm state error!", NULL, MB_OK);
return FALSE;
}
//code ends here
The bRet of above is always FALSE.How I can call SetCommState Successfully?
I need your help. Thanks.
|
|
|
|
|
Shouldn't it be SetCommState, not ::SetCommState?
Cheers,
Fredrik
"Felix qui potuit rerum cognoscere causas."
|
|
|
|
|
hi,
I met a problem when I using serialize/deserialize of CObject in VC++ 6.0. Who can kindly give some help?
I serialize a object array to store them in the disk file. When I try to deserialize them back from file. I found the time spent on this would increase exponentially with the size of file. When file is 500K, it need about 1 senconds. when file is 1M, it takes about 3 second... when file is 15M, it takes several minutes. I had hoped my program could handle file of handreds megabytes. this speed is unaccept for me.
regards,
jim wang
|
|
|
|
|
Have you profiled the code to see where the bottleneck is? Glowcode www.glowcode.com[^] is good for this. VC++ also has profiling capabilities.
The exponential increase doesn't seem right. It may be a combination of reading/parsing and allocating memory. If you are using the heap and that's a performance issue then there are fast heap managers around.
But I have to wonder why you are serializing a 15M file.
I can tell you that using pugXML (here on CP) in Memory Mapped File mode I can read and parse a 10M XML file in about .5 sec on a slow old 550Mhz P3.
Neville Franks, Author of ED for Windows. Free Trial at www.getsoft.com
|
|
|
|
|
When you start a thread using AfxBeginThread() does the thread function have to be a static member? Anyone know how to start a thread function that isn't static?
Mike Ellertson
|
|
|
|
|
Mike Ellertson wrote:
does the thread function have to be a static member?
Yes. Pass a pointer to the class as an LPVOID parameter then inside the static function call whatever member function using the pointer.
John
|
|
|
|
|
Mike Ellertson wrote:
Anyone know how to start a thread function that isn't static?
Take a look at this article[^].
Who is 'General Failure'? And why is he reading my harddisk?!?
|
|
|
|
|
The m_child is derive from CWnd, but it can't get focus, the caption of this child window is always gray.
m_child.Create( NULL, "OK", WS_VISIBLE | WS_CHILD | WS_CAPTION,
rc, this, 100, NULL );
|
|
|
|
|
You need to provide more information. What class is m_Child? Where are you creating it?
If this is on a dialog, you may be missing WS_TABSTOP. If you are inheriting from CStatic
then you will also have issues, as that passed focus to its parent.
You should also look up WM_GETDLGCODE.
etc.
Iain.
|
|
|
|