如何知道文件复制完成 [英] How to know a file is finished copying

查看:49
本文介绍了如何知道文件复制完成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 ReadDirectoryChangesW 来监视一个文件夹,如果我将一个大文件复制到该文件夹​​中,我会收到多个 FILE_ACTION_MODIFIED 消息,似乎每次 Windows 写入一大块文件时,您都会修改该文件每次通知.我尝试使用 CreateFile API 来检查文件是否可以被 AP 打开,但有时,某些文件总是被其他 AP 锁定,例如,如果您打开 Outlook,PST 会更新,但我的 AP 可以不能访问它,我们必须启动 Shadow Copy 才能打开它.所以我的问题是,如何知道一个文件复制完成了?

I’m using ReadDirectoryChangesW to spy a folder, if I’m copying a large file to the folder, I can receive multiple FILE_ACTION_MODIFIED messages, it seems each time windows writes a large chunk of the file, you get the file modified notification for each time. I tried to use CreateFile API to check if the file can open by AP or not, but sometime, some of files are always locked by other AP, for example, if you are opening the Outlook, the PST will update, but my AP can’t access it, we have to start Shadow Copy to open it. So my question is, how to know a file is finished copying?

推荐答案

这是一个非常hacky 性质的解决方案,但在非常棘手的情况下,您可以运行轮询循环来检查大小(或修改日期)文件.如果它在一段时间内没有改变,您可以有点安全地假设文件已完成复制.

This is a solution of a very hacky nature, but in a very hairy situation you can run a polling loop to check the size (or modified date) of the file. If it doesn't change for a while, you can somewhat safely assume that the file is finished copying.

这不是一般情况下的最佳解决方案,但考虑到在 OP 的情况下,问题约束排除了更好的解决方案.在考虑否决投票之前,请先考虑这一点.

This is not the optimal solution in the average case, but consider that in the OP's case better solutions are ruled out by the problem constraints. Think about this before you think of downvoting.

这篇关于如何知道文件复制完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆