在硬盘驱动器上对文件进行分类 [英] cataloging files on a hard drive

查看:80
本文介绍了在硬盘驱动器上对文件进行分类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好

我的一个项目涉及维护根据共享点站点上的文件类型分组的文件的动态索引.请帮助我解决使用哪种框架或编码语言.

Hello guys

One of my projects involves maintaining a dynamic index of files grouped according to file types on a sharepoint site . Please help me out guys as to what framework or coding language to use.

推荐答案

我认为您不需要.NET Framework之上的任何其他框架.重新使用过.

您可以使用System.IO.Directory.GetFiles收集所有文件并将其放入数据库中.如果使用参数System.IO.SearchOption.AllDirectories,则可以递归获取所有文件.

关于分组,我建议您设计数据库结构,使其支持所有必需的文件系统视图方式:分层结构(使用Windows Shell进行查看的方式)以及各种标记(例如文件扩展名).请注意,从文件系统的角度来看,没有这样的文件扩展名的概念(就像我在MS-DOS中使用的那样);这只是文件名的一部分;但是,Shell支持文件类型关联(与应用程序一起使用)以文件名结尾的形式的扩展名".

更困难的问题是:如何将索引与对文件系统所做的更改同步?您需要预订所有文件系统更改的所有事件,例如删除或创建文件和目录.您可以使用类System.IO.FileSystemWatcher进行操作,请参见 http://msdn.microsoft. com/en-us/library/system.io.filesystemwatcher.aspx [ ^ ].

您将需要使用一个单独的单线程(或者可能是一个单独的进程;在这种情况下,您应该创建一个专用于此目的的Windows服务)来重新索引文件系统的各个部分,以响应来自<实例的通知c3>并更新您的数据库.

这就是完成任务所需的全部知识.

—SA
I don''t think you need any other framework above .NET Framework you''re already using.

You can collect all files and put them in your data base using System.IO.Directory.GetFiles. You can get all files recursively if you use the parameter System.IO.SearchOption.AllDirectories.

As to grouping, I suggest you devise your data base structure the way it supports all required view it the file system: hierarchical (the way you see it using Windows Shell) and by all kind of tags such as file extension. Please be advised that there is no such notion such file extension from the stand point of the file system (as it used to me in MS-DOS); this is just a part of the file name; however, "extension" in the form of file name ending is supported by the Shell for file type associations (with applications).

More difficult problem is: how to synchronize your index with changes done to the file system? You need to subscribe to all events of all the file system changes such as deletion or creation of files and directories. You can do it using the class System.IO.FileSystemWatcher, see http://msdn.microsoft.com/en-us/library/system.io.filesystemwatcher.aspx[^].

You will need to dedicate a separate single thread (or maybe a separate process; in this case you should create a Windows Service dedicated to this purpose) used to re-index parts of your file system in response to the notifications from your instance of FileSystemWatcher and update your data base.

That''s all you need to know to accomplish your task.

—SA


这篇关于在硬盘驱动器上对文件进行分类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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