以编程方式确定文件的碎片状态
是否可以确定特定文件的碎片状态(即该文件占用的不同碎片的数量)? 如果是这样,如何使用 .net 来完成此操作?
动机是这样的:我的应用程序将数据保存在 FileStream 中,按需更改其大小。这最终会导致文件碎片化。我想监视文件的碎片状态,并据此决定是否应复制该文件并用新文件替换该文件(从而在不更改 MFT 的情况下对其进行“碎片整理”)。
Is it possible to determine a specific file's fragmentation status (that is, the amount of distinct fragments this file occupies)?
If so, how can this be done using .net?
The motivation is this: my application is keeping data in a FileStream, changing its size on-demand. This eventually causes the file to be fragmented. I'd like to monitor the file's fragmentation status, and based upon that - make a decision if the file should be copied and replaced by a new file (thus "defragmenting" it without making changes to the MFT).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这完全属于“过早优化”范畴。根本不能保证您会导致碎片,光盘很可能在文件末尾有未提交的簇,而且经常如此。也许更重要的是,.NET 框架中没有任何内容可以让您检测或修复此问题。访问卷的 MFT 需要非托管代码和管理员权限。
对磁盘进行碎片整理是一项正常的机器维护任务。 Win7就自动了。
This squarely falls in the "premature optimization" category. It is not at all guaranteed that you'll cause fragmentation, the disc may well have uncommitted clusters past the file end and often does. Perhaps more the point, there isn't anything in the .NET framework that allows you to detect or fix this. Accessing the volume's MFT requires unmanaged code and admin privileges.
Defragging a disk is a normal machine maintenance task. It became automatic with Win7.