问题描述
当我使用File.Copy(path1,path2,true)函数复制文件多次失败时。
path2有empy内容,我使用API GetLastError,返回值为零。
或使用try catch,但它没有抛出异常。
然后我用path2打开目录,文件内容为空,为什么?
我怎么能成功复制文件?
我查看关于path1和path2的代码,我确定路径是正确的,没错。
我只需要做两步:
(1).opendialog并设置path1例如c:\ a.txt,将其复制到path2例如c:\ temp.txt。
(2).load文件第二次,opendialgo并将path1设置为新值,例如c:\b.txt。
将它复制到path2 c:\ temp.txt
但第二次,temp.txt是空内容,这意味着复制失败,为什么,我无法理解原因。
我尝试过:
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:
try
{
File.Copy(filePath, tempPath, true);
uint iiii = GetLastError();
}
catch (Exception e)
{
throw e;
}
<pre lang="c#">
推荐答案
这篇关于复制多次时为什么复制文件失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!