我在.NET中编写目录扫描程序.
对于每个文件/目录,我需要以下信息.
class Info {
public bool IsDirectory;
public string Path;
public DateTime ModifiedDate;
public DateTime CreatedDate;
}
Run Code Online (Sandbox Code Playgroud)
我有这个功能:
static List<Info> RecursiveMovieFolderScan(string path){
var info = new List<Info>();
var dirInfo = new DirectoryInfo(path);
foreach (var dir in dirInfo.GetDirectories()) {
info.Add(new Info() {
IsDirectory = true,
CreatedDate = dir.CreationTimeUtc,
ModifiedDate = dir.LastWriteTimeUtc,
Path = dir.FullName
});
info.AddRange(RecursiveMovieFolderScan(dir.FullName));
}
foreach (var file in dirInfo.GetFiles()) {
info.Add(new Info()
{
IsDirectory = false,
CreatedDate = file.CreationTimeUtc,
ModifiedDate = file.LastWriteTimeUtc,
Path = file.FullName
});
} …Run Code Online (Sandbox Code Playgroud) 我试图确定用户是否使用MS Log Parser 2.2从FTP下载了一个文件
虽然我已经使用了几个样本查询,但我还是无法获得解析器SQL查询.
Water Down Parser Query不起作用:
strSQL = "SELECT date,COUNT(*) AS downloads,c-ip "
strSQL = strSQL & "FROM C:\temp\Log\*.log "
strSQL = strSQL & "WHERE cs-method='RETR' "
strSQL = strSQL & "GROUP BY date,c-ip "
Run Code Online (Sandbox Code Playgroud)
错误:
RecordSet cannot be used at this time [Unknown Error]
Run Code Online (Sandbox Code Playgroud)
题:
如何创建查询:
- SELECT Date and Time of download
- Where user = 'xxx'
- WHERE RETR = is a download
- WHERE Filename = u_ex150709.log or xxx
Run Code Online (Sandbox Code Playgroud)
C#中的答案也很受欢迎
VB.net代码:
Dim rsLP …Run Code Online (Sandbox Code Playgroud) 我想遍历我的硬盘上的目录,并在所有文件中搜索特定的搜索字符串.这听起来像是可以(或应该)并行完成的完美候选者,因为IO相当慢.
传统上,我会编写一个递归函数来查找和处理当前目录中的所有文件,然后递归到该目录中的所有目录.我想知道如何将其修改为更平行.起初我简单地修改了:
foreach (string directory in directories) { ... }
Run Code Online (Sandbox Code Playgroud)
至
Parallel.ForEach(directories, (directory) => { ... })
Run Code Online (Sandbox Code Playgroud)
但我觉得这可能会创建太多的任务并使自己陷入困境,特别是在尝试重新分配到UI线程时.我也觉得任务的数量是不可预测的,这可能不是一个平行(这是一个词?)这个任务的有效方法.
有没有人成功做过这样的事情?这样做有什么建议?
所以我有这个例程:
public static IEnumerable<string> GetFiles( string path, string[] searchPatterns, SearchOption searchOption = SearchOption.TopDirectoryOnly) {
return searchPatterns.AsParallel()
.SelectMany(searchPattern =>
Directory.EnumerateFiles(path, searchPattern, searchOption))
.OrderBy<string, string>( (f) => f)
.Distinct<string>();
}
Run Code Online (Sandbox Code Playgroud)
它的工作,但按名称排序文件,我需要订购其创建日期返回的文件.如果项目是例程中的字符串,我该如何排序呢?我想使用枚举原因文件预计超过1k.
谢谢.