是否有更简单的方法来协调文件列表和具有子文件夹/文件的目录以查找更改?
我有一个包含文件列表(路径+文件名)的 SQL Server 表,以及一个包含多个层和每个层中的文件的文件夹。我正在寻找一种方法来协调两者,而不必两次处理列表。目前,我正在这样做:
For Each f as FileInfo In FileListFromDatabase
If f.Exists is False, mark it as deleted in the database
Next
For Each f as FileInfo In RecursiveListOFFilesOnDisk
If Not FileExistsInDatabase, then add it
Next
有更好的方法吗?我想避免将所有匹配文件(其中大多数)转换为 FileInfo 对象两次。由于我首先是一名 T-SQL 开发人员,因此我想象了类似两个不匹配列表的 OUTER JOIN 的情况。类似于 LINQ 的东西吗?
I have a SQL Server table with a list of files (path + filename), and a folder with multiple layers and files in each layer. I'm looking for a way to reconcile the two without having to process the list twice. Currently, I'm doing this:
For Each f as FileInfo In FileListFromDatabase
If f.Exists is False, mark it as deleted in the database
Next
For Each f as FileInfo In RecursiveListOFFilesOnDisk
If Not FileExistsInDatabase, then add it
Next
Is there a better way to do this? I'd like to avoid converting all the matching files (of which most will be) to FileInfo objects twice. Since I'm a T-SQL developer first, I'm picturing something like an OUTER JOIN of the two lists where they don't match. Something LINQ-ish?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想不出任何像您想要的那样简洁的解决方案,但如果您担心 IO 性能,则不必查找每个现有文件两次,只需读取所有文件位置并在内存中完成所有操作即可。
如果存储在数据库中的路径名可能与文件系统中的路径名不同,您可能需要对此进行调整。
I can't think of any solution as neat as you want, but if you're worrying about IO performance, instead of finding each existing file twice, just read in all the file locations and do it all in memory.
If the path names stored in the DB could have a different case than the ones in the filesystem you might have to adjust for that though.