如果检测将File.Move需要“复制 - >删除“或只是改变文件系统表位置 [英] Detecting if File.Move will require 'Copy -> Delete' or just alter location in the file system table

查看:268
本文介绍了如果检测将File.Move需要“复制 - >删除“或只是改变文件系统表位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

免责声明:
我承认,马上我的无知关于对文件系统如何作用的细节相当数量。我一直在使用NTFS了这么久,我可以推断什么是基于行为我亲眼目睹了,还有什么我已经从肉鸡在互联网上了解到事情 - 不过...

Disclaimer: I will admit straight away I have a fair amount of ignorance regarding the details on how file systems function. I have been using NTFS for so long that I can extrapolate what is going on based on behaviors I have witnessed, as well as whatever I have learned from dorking on the internet - however...

我希望有一种方法来检测是否正在从'位置'到'位置b'的文件时,操作是否将需要相当于'File.Copy - > File.Delete'或如果它不会复制实际的文件数据,而只是更新了主文件表或类似的位置。

I was hoping that there is a way to detect if when moving a file from 'location A' to 'location B', whether the operation will require the equivalent of 'File.Copy -> File.Delete' or if it will not copy the actual file data, but just update the location in the 'master file table' or the like.

有关各种目的,我有时移动大数大文件。我喜欢在UI报告进度。

For various purposes, I sometimes move large numbers of large files. I like to report progress in the UI.

我意识到,当我打电话File.Move并从位置的一个磁盘/分区到另一个移动一个文件,该功能将有效地以'拷贝文件数据 - >删除的磁盘/分区间。当遇到这种情况,我想能够检测到这会发生,所以我可以使用代码,我已经撰写,将复制的文件,并给予详细的进度报告作为个字节传送这样我就可以经常更新UI中的进度条。

I realize that when I call File.Move and move a file from a location on one disk/partition to another, that the function will effectively have to 'copy file data -> delete' between the disks / partitions. When it encounters this situation, I want to be able to detect that this will happen so I can use code I have authored that will copy the file and give detailed progress reporting as bytes are transferred so I can update progress bars in the UI frequently.

当它是在相同的磁盘/分区,如主文件表更新的位置是如此之快,我只是更新进度条时file.Move功能完成对每一个文件,我批感动。

When it is on the same disk/partition, as updating the location in the master file table is so fast, I simply update the progress bar when the file.Move function completes for each file I am batch moving.

使用.NET 4(C#),是否有可能通过其他手段来检测是否调用File.Move将需要相当于?'复制 - >删除操作,或将只更新文件表,而不是复制文件数据

Using .NET 4 (C#), is it possible to detect through other means whether calling the File.Move will require an equivalent 'copy -> delete' operation or will simply update a file table and not copy the file data?

编辑:

正如我注意到,在下面的评论,我如何想可能这个的可能的完成将是检测一个给定的源文件的位置和目标文件位置位于在同一物理磁盘和放大器;分区,如果是的话,就意味着我能够准确预测的行为,并决定调用什么功能 - 内置File.Move功能的即时附近的更新文件系统表,我相信会发生移动到同一个磁盘时/部分还是我更详细的进度报告每一个X个字节复制自定义文件拷贝代码。 。文件传输速度可以在机器上我的程序运行,所以我希望能够报告详细的进度/尽可能目前传输速度相差很大。

As I note in comments below, possibilities on how I thought this might be done would be to detect if a given source file location and destination file location are located on the same physical disk & partition, and if so, would this mean I could accurately anticipate the behavior and decide what functions to call - the built in File.Move function for the 'near instant' update file system table that I believe occurs when moving to same disk/part, or my more detailed 'report progress every 'x' bytes copied' custom file copy code. File transfer speeds can vary greatly on the machines my programs will run on so I like to be able to report detailed progress / present transfer speed when possible.

请注意 - 该程序可以是使用其中可以使用不同的物理磁盘具有相同的根路径网络UNC路径即:\\somename\shares\workfolder\project可以是不同的物理磁盘上然后\\somename\shares \workfoldder\otherproject。所以,我需要检测的分区ID或物理磁盘ID的方法,看看对同一个磁盘/分区源和目标文件夹。

Note - The program may be using network UNC paths which can be using different physical disks with the same root path i.e.: \\somename\shares\workfolder\project may be on a different physical disk then \\somename\shares\workfoldder\otherproject. So I would need a method for detecting the partition ID or physical disk ID to see if a source and destination folder on on the same disk/partition.

感谢您

推荐答案

您总是可以p / Invoke来的 MoveFileWithProgress 。从粗略的阅读,它看起来像它会给你更精细的进步,当一个文件被复制,而不是感动。

You could always P/Invoke to MoveFileWithProgress. From a cursory reading, it looks like it'll give you more granular progress when a file is copied, rather than moved.

另外,总有的 SHFileOperation ,which'll给你的Windows资源管理器用户界面和语义。

Alternatively, there's always SHFileOperation, which'll give you the Windows Explorer UI and semantics.

这篇关于如果检测将File.Move需要“复制 - >删除“或只是改变文件系统表位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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