|
-
August 2nd, 2006, 01:36 AM
#1
How to copy file from one place to another....
Hi !!
In my application, I am downloading one file to my application path.Some times it is not downloading total file.In that my application is crashing.
For that I want to download that file to another place.If it is dowloaded correctly,then it is to copy to my application path.
For downloading,I wrote the code as follows....
int createFileMask = CFile::modeCreate | CFile::modeWrite | CFile::typeBinary;
CFile destFile(strDestFile,createFileMask );
while(byteswrite = pTargFile->Read(filebuf,512)){
destFile.Write(filebuf, byteswrite);
}
// Download ended, close file
destFile.Close();
Can any one please give me the solution for this problem..
And can I use the CopyFileEx method to solve this??If, How can I use this function..
Thanks & Regards,
klvin.
-
August 2nd, 2006, 01:49 AM
#2
Re: How to copy file from one place to another....
Where does it crash, which line ?
Are you asking how to copy file to new destination after download is complete ?
Regards,
Ramkrishna Pawar
-
August 2nd, 2006, 02:16 AM
#3
Re: How to copy file from one place to another....
Hi krishnaa,
My application is crashing when it is not downloading file fully because of server problems..
So that I want to download the file to another path.After file is completely downloded then i want to copy the downloaded file to my application path.
Can you give me the solution for this....
Thanks & regards,
klvin
-
August 2nd, 2006, 02:28 AM
#4
Re: How to copy file from one place to another....
I didn’t get it, from where you are downloading the file? if its from the internet simply use ::URLDownloadToFile ().
if its from a mapped network drive on your server you can use ::SHFileOperation ()
Cheers
-
August 2nd, 2006, 02:30 AM
#5
Re: How to copy file from one place to another....
FYI: the best way to copy files in Windows - using ::CopyFile API
-
August 3rd, 2006, 01:45 AM
#6
Re: How to copy file from one place to another....
Hi !!
Thanks for the reply.
I tried with ::CopyFile(...).It is working.It is copying the downloaded file to my application path.
But, How Can I check the condition whether the file is fully downloaded or not before copying the file??
If the file is fully download, then only it should copy that file to application path.
Can you please give me solution, How to check the condition?????
Code:
CStdioFile *pTargFile = NULL;
pTargFile =
netSession.OpenURL(......)
CString strCurrentDir,str;
mapURLs.Lookup(_T("app_cwd"), strCurrentDir);
str = strCurrentDir + "Downloads\\";
::CreateDirectory(str,NULL);
strDownldFile.Format(_T("%s%s"),
str,
fl);
strDestFile.Format (_T("%s%s"),
strCurrentDir,
fl);
int createFileMask = CFile::modeCreate | CFile::modeWrite | CFile::typeBinary;
CFile destFile(strDownldFile,createFileMask );
while(byteswrite = pTargFile->Read(filebuf,512)){
destFile.Write(filebuf, byteswrite);
}
// Download ended, close file
destFile.Close();
After destFile.Close()..I have to check condition and copythe file....
Thanks & Regards,
klvin.
Last edited by klvin; August 3rd, 2006 at 01:53 AM.
-
August 3rd, 2006, 02:14 AM
#7
Re: How to copy file from one place to another....
Check out For DownLoadComplete() and DocumentComplete Event. Have a look in MSDN for More details. for More detail have a look on this Thread.or you can use InternetQueryDataAvailable()
Thanx
Last edited by humptydumpty; August 3rd, 2006 at 02:16 AM.
-
August 3rd, 2006, 04:34 AM
#8
Re: How to copy file from one place to another....
Hi humptydumpty,
Thanks for the reply.
But I don't know how to use DownloadComplete() and all..
Can you give me idea,how can I use them relatedly to my project.
Thanks&Regards,
klvin.
-
August 3rd, 2006, 04:41 AM
#9
Re: How to copy file from one place to another....
Hi,
Since you have finished reading the bytes and have written them to the destfile, it means that the download is done. You dont need to check any
condition after calling destFile.Close(). You can copy it right away.
Or am i missing something in your question ?
-
August 3rd, 2006, 04:51 AM
#10
Re: How to copy file from one place to another....
-
August 3rd, 2006, 07:41 AM
#11
Re: How to copy file from one place to another....
 Originally Posted by klvin
Hi humptydumpty,
Thanks for the reply.
But I don't know how to use DownloadComplete() and all..
Can you give me idea,how can I use them relatedly to my project.
Thanks&Regards,
klvin.
Very simple:
Code:
::URLDownloadToFile(0,"http://www.yahoo.com/index.html","c:\\index.html",0,0);
Cheers
-
August 3rd, 2006, 08:00 AM
#12
Re: How to copy file from one place to another....
 Originally Posted by humptydumpty
Check out For DownLoadComplete() and DocumentComplete Event.
Not applicable to projects which do not use WebBrowser control or Html/Dhtml controls or Internet explorer automation.
@klvin
URLDownloadToFile is best, and then CopyFile can copy the downloaded file, why write a lot of code for functionality which is already there.
Regards,
Ramkrishna Pawar
-
August 4th, 2006, 02:09 AM
#13
Re: How to copy file from one place to another....
Hi !!
Thanks for the reply Krishnaa..
But, my doubt is ..
How can I know Whether the file was fully downloaded or not????
Thanks&Regards,
klvin.
-
August 4th, 2006, 05:07 AM
#14
Re: How to copy file from one place to another....
 Originally Posted by klvin
Hi !!
Thanks for the reply Krishnaa..
But, my doubt is ..
How can I know Whether the file was fully downloaded or not????
Thanks&Regards,
klvin.
If you using ::URLDownloadToFile() the function wont return until the download finished.
Cheers
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|