Click here to Skip to main content
15,896,063 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
when i use File.Copy(path1,path2,true) function to copy file many times it failed。
path2 has empy content,and i use API GetLastError,the return value is zero.
or use try catch,but it didn't throw exception.
and then i open the directory with path2,the file content is empty,why?
how shall i do can success copy file any times?

I review my code about path1,and path2,i'm sure the path is correct and has no mistake.
I just do two steps:
(1).opendialog and set path1 for example c:\a.txt ,copy it to path2 for example c:\temp.txt.
(2).load file second times,opendialgo and set path1 to new value,for example c:\b.txt.
copy it to path2 c:\temp.txt
but second times, temp.txt is empty content,that means copy failed,why,i cann't understand the reason.

What I have tried:

C#
try
{
   File.Copy(filePath, tempPath, true);
   uint iiii = GetLastError();
}
 catch (Exception e)
{
    throw e;
}
<pre lang="c#">
Posted
Updated 24-Nov-16 23:01pm
v6

1 solution

If you did not get an exception the copy operation succeeded.

If the destination file exists after copying but is of size zero (empty), the conclusion is that the source file is empty too.

You might perform a file compare after successful copying to check if the files are identical:
How to create a File-Compare function in Visual C#[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900