2nd try at copying a file: copyfile() returns success but creates empty destination file 
Author Message
 2nd try at copying a file: copyfile() returns success but creates empty destination file

In an effort to respond to a user request for an in-program way of
copying a read-only file using the framework's 'File Save As' facility,
I placed the following code in my MFC app, in one of my CDocument class
Serialize(ar) functions (In the code below, m_Filename is captured
during the load operation so it is available for a subsequent copy
operation)

void COaaDoc::Serialize(CArchive& ar)
{
 //Notes:
  if (ar.IsStoring())
  {
   //Write section added 9/2/98 for FileSaveAs support
   ar.Flush() ; //must call before accessing file pointer
   CString fname = ar.GetFile()->GetFilePath() ;
   BOOL result = CopyFile( m_Filename.GetBuffer( m_Filename.GetLength()
),
        fname.GetBuffer( fname.GetLength() ),
        FALSE ) ;

  }
  else
  {....
   }

The call succeeds (returns 1) and the destination file is created,  but
has 0 length.

Any ideas what I'm doing wrong here, or a better way of doing this from
code?

TIA,



Mon, 19 Feb 2001 03:00:00 GMT  
 2nd try at copying a file: copyfile() returns success but creates empty destination file

Quote:

>In an effort to respond to a user request for an in-program way of
>copying a read-only file using the framework's 'File Save As' facility,
>I placed the following code in my MFC app, in one of my CDocument class
>Serialize(ar) functions (In the code below, m_Filename is captured
>during the load operation so it is available for a subsequent copy
>operation)

>void COaaDoc::Serialize(CArchive& ar)
>{
> //Notes:
>  if (ar.IsStoring())
>  {
>   //Write section added 9/2/98 for FileSaveAs support
>   ar.Flush() ; //must call before accessing file pointer
>   CString fname = ar.GetFile()->GetFilePath() ;
>   BOOL result = CopyFile( m_Filename.GetBuffer( m_Filename.GetLength()
>),
>        fname.GetBuffer( fname.GetLength() ),
>        FALSE ) ;

>  }
>  else
>  {....
>   }

>The call succeeds (returns 1) and the destination file is created,  but
>has 0 length.

>Any ideas what I'm doing wrong here, or a better way of doing this from
>code?

>TIA,

Have you tried copying the file manually at the command prompt, and see if
it copies with a non-zero length? It may not be your code at all. I can't
see anything wrong with it. You HAVE checked to make sure the original is
not 0-length, haven't you?(!)

_ _
o o   Jason Teagle
 <

Please ONLY respond via e-mail if you want to catch my attention - I don't
necessarily look at the newsgroups all the time.



Tue, 20 Feb 2001 03:00:00 GMT  
 2nd try at copying a file: copyfile() returns success but creates empty destination file
Do you have to close the input file before you activate they copy
so that WIN doesn't think the file is "in-use" and won't let it be read ?
Quote:

>>The call succeeds (returns 1) and the destination file is created,  but
>>has 0 length.

>>Any ideas what I'm doing wrong here, or a better way of doing this from
>>code?

>>TIA,

>Have you tried copying the file manually at the command prompt, and see if
>it copies with a non-zero length? It may not be your code at all. I can't
>see anything wrong with it. You HAVE checked to make sure the original is
>not 0-length, haven't you?(!)



Tue, 20 Feb 2001 03:00:00 GMT  
 2nd try at copying a file: copyfile() returns success but creates empty destination file
Jay,

Good point!  I definitely have the file open, as it is being viewed in the
application when the user selects 'Save As...'.  I'll try that tonite!

Frank

Quote:

> Do you have to close the input file before you activate they copy
> so that WIN doesn't think the file is "in-use" and won't let it be read ?


> >>The call succeeds (returns 1) and the destination file is created,  but
> >>has 0 length.

> >>Any ideas what I'm doing wrong here, or a better way of doing this from
> >>code?

> >>TIA,

> >Have you tried copying the file manually at the command prompt, and see if
> >it copies with a non-zero length? It may not be your code at all. I can't
> >see anything wrong with it. You HAVE checked to make sure the original is
> >not 0-length, haven't you?(!)



Tue, 20 Feb 2001 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. 2nd try at copying a file: copyfile() returns success but creates empty destination file

2. 2nd try: need a C library file for reading Windows-style .INI files

3. 1st try no link, 2nd try link?

4. Txt-File Read to sting Trouble (2nd try..)

5. Trying to compile for Win95 without success :-(

6. Trying to print a CDialog with no success!

7. Empty Buffer Returned by Read File (Some Times)

8. Copy whole dir with copyfile(...)

9. Regsvr32 does not return anything (Success or Failure)

10. ActiveX creation fails, but returns success

11. Regsvr32 does not return anything (neither success nor failure)

12. IShellLink::GetIconLocation returns success but doesn't fill buffer

 

 
Powered by phpBB® Forum Software