File.Move以外的文件移动方法更快

Jam*_*son 8 c# console-application

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

首先,我正在一个目录中工作,如果不是更多的话,那里有大约4,000,000个文件.我正在一个数据库中工作,每个文件都有一行,然后是一些.

现在使用SQL相对较快,瓶颈是当我使用File.Move()每个移动需要18秒才能完成.

有比这更快的方式File.Move()吗?

这是瓶颈:

File.Move(Path.Combine(location, fileName), Path.Combine(rootDir, fileYear, fileMonth, fileName));
Run Code Online (Sandbox Code Playgroud)

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

如果需要,我可以显示其他代码,但实际上上面是唯一的当前瓶颈.

Jam*_*son 14

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

它现在将在大约35天内运行,而不是625天.

FileInfo fileinfo = new FileInfo(Path.Combine(location, fileName));
fileinfo.MoveTo(Path.Combine(rootDir, fileYear, fileMonth, fileName));
Run Code Online (Sandbox Code Playgroud)