|
I have to get the total count of the files present in a folder.I have to do a file transfer from that folder to another on a button click.Any help?Im using vc++
|
|
|
|
|
try FindFirstFile() and FindNextFile() or its MFC wrapper CFileFind to find the number of files in a folder
If you want to copy the entire contents of folder at once use SHFileOperation or if you want to copy one by one, use CopyFile() .
|
|
|
|
|
Please check my code...
void CMydlgtestDlg::Oncount()
{
int count=0;
CFileFind f;
CString file="D:\\mframes";
if(f.FindFile(LPCTSTR(file)))
{
count++;
f.FindNextFile();
}
AfxMessageBox(count);
|
|
|
|
|
Like this..
int count=0;
CFileFind f;
CString file="D:\\mframes\\*.*";
BOOL bFound = f.FindFile(file);
while( bFound )
{
bFound = f.FindNextFile();
if( !f.IsDirectory())
{
count++;
}
}
modified on Tuesday, June 24, 2008 2:14 AM
|
|
|
|
|
i get a debug assertion failure when the code is run.it is written inside a member function of a button.
|
|
|
|
|
Press the Retry button while debugging and check the call stack to find the assertion location.
|
|
|
|
|
I gave an AfxMessageBox at the end ,it is there the error is displayed..it is just given to display the count;
|
|
|
|
|
You cannot put a int variable directly in a AfxMessageBox() function like in VB.If you want to show the count in message box, modify as follows
CString csCount;
csCount.Format( _T("%d"), count );
AfxMessageBox( csCount );
|
|
|
|
|
Thanks..it worked now...Now how to copy the files?
I have to copy all files from "D:\mframes" to "D:\new"
Have declared both as below.
mframes is declared as such to copy all files in it.
CString file="D:\\mframes\\*.*"; <br />
CString next="D:\\new";
|
|
|
|
|
CFileFind f;
CString file="D:\\mframes\\*.*";
CString next="D:\\new\\";
BOOL bFound = f.FindFile(file);
while( bFound )
{
bFound = f.FindNextFile();
if( !f.IsDirectory())
{
CString csFilePath = f.GetFilePath();
CString csNewPath = next + f.GetFileName();
CopyFile( csFilePath, csNewPath, TRUE );
}
}
|
|
|
|
|
Count is one more than the actual and the fioles are not copied to d:\new.rather they are just copied to d:\
|
|
|
|
|
ok. Debug and find the cause...
BTW did you notice the "\\" in the end of line CString next="D:\\new\\"; in the above post?
|
|
|
|
|
|
yea..now it gets copied to d:new.
Here i have already specified the folders.what if i want to check whether the directory i am going to create exists?
|
|
|
|
|
|
Gives an error "'PathFileExists' : undeclared identifier"
|
|
|
|
|
projectip wrote: Now how to copy the files?
I have to copy all files from "D:\mframes" to "D:\new"
As has already been mentioned, use SHFileOperation() .
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
There is an example in this MSDN page[^] which might help you.
Nobody can give you wiser advice than yourself. - Cicero
.·´¯`·->Rajesh<-·´¯`·.
Codeproject.com: Visual C++ MVP
|
|
|
|
|
I have created an MFC application in Visual Studio.
I have x and y values to be plotted for the graph which will display a curve.
I have no idea at all how to draw a graph in VS.
Is there any free tool, a fast and easy method I can incorporate into my application?
I just want to display a simple graph.
Ema
|
|
|
|
|
|
I want to send a string between 2 dialog. So I try to use SendMessage() with WM_COPYDATA message
Here is the code in send dialog
COPYDATASTRUCT cds;
....
::SendMessage(hWnd, WM_COPYDATA, (WPARAM) m_hWnd, (LPARAM) &cds );
And receive dialog code:
BEGIN_MESSAGE_MAP(RcvDlg, CDialog)
.....
ON_WM_COPYDATA()
END_MESSAGE_MAP()
BOOL RcvDlg::OnCopyData(){
...
}
It works, but while sending messeage, it locks the send dialog. So I want to change to another way, PostMessage. But I don't know how to implement. I tried to look on the internet, but cannot find what I want.
Can anyone help me? Thanks in advance,
|
|
|
|
|
Don't you see the following comments just below the help of WM_COPYDATA in MSDN[^]
An application must use the SendMessage function to send this message, not the PostMessage function.
|
|
|
|
|
oh, that's why I wasn't success.
thank you very much, Naveen.
So this means that when dialog A sends a string message to dialog B, it must be locked until receive the reply.
Is it correct??
|
|
|
|
|
tataxin wrote: So this means that when dialog A sends a string message to dialog B, it must be locked until receive the reply.
Is it correct??
Yes.
|
|
|
|
|