FileInfo.Length 始终显示文件总大小,而不是实际的当前大小
我正在尝试使用 File.Copy([FileName]) 命令监视大文件复制过程的进度(无需自己手动复制数据字节)。
所以我想做的是获取正在复制的文件的长度,并将其与目标文件的长度进行比较。这会让我对复制进度有一个很好的了解。
唯一的问题是目标文件上的 FileInfo.Length 属性返回正在复制的文件的总大小,而不是磁盘上文件的实际大小。还有其他方法可以获取这些数据吗? 谢谢, 克里斯
EDIT (Moved from below -- was submitted as an answer by OP)
我查看了链接,这根本不是我想要的。我只想在文件很大时显示文件复制的进度(复制时间超过 3 秒)。
大多数文件大约需要 1/4 秒,但也有一些文件大约有 600+MB,通过网络复制需要一些时间。
我所需要的只是如何获取目标目录中部分复制的文件的实际文件大小。
(由于我在这里没有帐户,所以它不允许我发布对您对我的问题的答复的答复,因此它被显示为答案,即使它不是。)
谢谢,克里斯
I am trying to monitor the progress of a large file copy proceedure (without manually copying the bytes of data myself) using the File.Copy([FileName])
command.
So what I am trying to do is get the length of the file being copied, and compare that to the length of the destination file. This would give me a good sense of the copy progress.
The only problem is that the FileInfo.Length
property on the destination file returns the total size of the file being copied, not the actual size of the file on the disk. Is there any other way to get this data?
Thanks,
Chris
EDIT (Moved from below -- was submitted as an answer by OP)
I looked at the link, and that is not at all what I want. I only want to show the progress of the file copy if the file is large (taking more than 3 seconds to copy).
The majority of the files take about 1/4 of a second, but there are a few that are ~600+MB, which take some time to copy over the network.
All I need is how to get the actual file size of the partially copied file in the destination directory.
(Since I don't have an account here, it did not let me post a reply to your reply to my question, so it is being shown as an answer, even though it is not.)
Thanks, Chris
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用流自行执行复制操作并显示进度:
You can do the copy operation yourself using streams and display the progress: