【发布时间】:2017-11-21 23:58:53
【问题描述】:
我有一个源文件夹FolderSource,其中包含在过去 6 个月内创建的 200K 文件。每天都会向此文件夹添加新文件(大约 10k 到 11k)。
如果最近 30 天内创建的文件在 FolderArchiveA、FolderArchiveB、FolderArchiveC 中不存在,我需要将它们复制到 FolderDestination
这是我的算法
1. Get one Filename from SourceFolder where CreatedDate > CurrentDate - 30
2. If Filename Exists in FolderArchiveA go to step 6
3. If Filename Exists in FolderArchiveB go to step 6
4. If Filename Exists in FolderArchiveC go to step 6
5. Copy File defined in FileName to FolderDestination
6. If there are more files to be processed, go to Step 1
我用 C# 编写了这个,但我要使用 FBAF(想想 RBAR,但带有文件)。执行需要 40 多分钟。
还有其他方法可以让我使用 Powershell 或 XCopy 更有效地编写代码吗?
【问题讨论】:
-
很容易。查找
Get-ChildItem和Where-Object。它利用了System.IO.FileInfo和System.IO.DirectoryInfo.NET 类。 -
您是否检查过流程的哪一部分具体是瓶颈?您可能只是受到磁盘 i/o 的限制。
-
@RajMore,如果这是一个长时间运行的服务,我会将所有文件名加载到内存中,添加一个文件系统观察器来维护它(以及定期捕获所有解析器)并在那个。
-
如果
FolderDestination中已经存在文件怎么办? -
如果文件已经存在,覆盖
标签: c# .net powershell xcopy