[英]how to copy already opened file?
I have a handle to a file, it is opened. 我有一个文件句柄,它打开了。
HANDLE h = ::CreateFile(...)
I would like to copy this file. 我想复制这个文件。 How to do that?
怎么做? I would like to do something like this:
我想做这样的事情:
CopyFile(h, "new_file.dat");
I know there is CopyFile(fileName, newFileName)
function, but it seems that I would have to close my handle before using this calling this function. 我知道有
CopyFile(fileName, newFileName)
函数,但似乎在使用this函数调用此函数之前我必须关闭我的句柄。 Is there another way of doing the copy? 还有其他方法可以复制吗?
I guess you are working in windows. 我想你在windows工作。 The problem is that in windows when you open a file it by default gets blocked for other opens (Copy also opens the file).
问题是,在Windows打开文件时,默认情况下会阻止其他打开(复制也会打开文件)。 As I know CreateFile has a flag that allows to open file in shared mode.
据我所知,CreateFile有一个允许以共享模式打开文件的标志。 That flag by definition should solve your problem.
根据定义,该标志应解决您的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.