File.Move以外的更快文件移动方法 [英] Faster file move method other than File.Move

查看:298
本文介绍了File.Move以外的更快文件移动方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个控制台应用程序,大约需要625天才能完成。除非有办法使它更快。

I have a console application that is going to take about 625 days to complete. Unless there is a way to make it faster.

首先,我正在一个包含大约4,000,000个文件的目录中工作。我正在一个数据库中工作,每个文件中都有一行,然后每个文件中都有一行。

First off I am working in a directory that has around 4,000,000 files in if not more. I'm working in a database that has a row for each file and then some.

现在使用SQL的速度相对较快,瓶颈在于使用 File.Move()每一步需要18秒才能完成。

Now working with the SQL is relatively fast, the bottleneck is when I use File.Move() each move takes 18 seconds to complete.

有没有比 File.Move()?

这是瓶颈:

File.Move(Path.Combine(location, fileName), Path.Combine(rootDir, fileYear, fileMonth, fileName));

所有其他代码的运行速度都非常快。我需要做的就是将一个文件移到新位置,然后更新数据库位置字段。

All of the other code runs pretty fast. All I need to do is move one file to a new location and then update the database location field.

如果需要,我可以显示其他代码,但实际上,上面是

I can show other code if needed, but really the above is the only current bottleneck.

推荐答案

事实证明,从File.Move切换到设置FileInfo并使用.MoveTo可以显着提高速度。

It turns out switching from File.Move to setting up a FileInfo and using .MoveTo increased the speed significantly.

现在运行大约35天,而不是625天。

It will run in about 35 days now as opposed to 625 days.

FileInfo fileinfo = new FileInfo(Path.Combine(location, fileName));
fileinfo.MoveTo(Path.Combine(rootDir, fileYear, fileMonth, fileName));

这篇关于File.Move以外的更快文件移动方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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