我有这个代码:
private void SearchForDoc()
{
try
{
outputtext = @"c:\temp\outputtxt";
outputphotos = @"c:\temp\outputphotos";
temptxt = @"c:\temp\txtfiles";
tempphotos = @"c:\temp\photosfiles";
if (!Directory.Exists(temptxt))
{
Directory.CreateDirectory(temptxt);
}
if (!Directory.Exists(tempphotos))
{
Directory.CreateDirectory(tempphotos);
}
if (!Directory.Exists(outputtext))
{
Directory.CreateDirectory(outputtext);
}
if (!Directory.Exists(outputphotos))
{
Directory.CreateDirectory(outputphotos);
}
t = Environment.GetEnvironmentVariable(Environment.GetFolderPath(Environment.SpecialFolder.Personal));
ApplyAllFiles(t,ProcessFile(t);
for (int i = 0; i < textfiles.Length; i++)
{
FileInfo fi = new FileInfo((textfiles[i]));
DirectoryInfo d = new DirectoryInfo(temptxt);
long dirSize = DirSize(d);
if ((dirSize + fi.Length) <= 8388608)
fi.CopyTo(temptxt + "\\" + fi.Name, true);
else
break;
}
然后在这之后我有两种方法:
static void ProcessFile(string path) {/* ... */}
static void ApplyAllFiles(string folder, Action<string> fileAction)
{
foreach (string file in Directory.GetFiles(folder))
{
fileAction(file);
}
foreach (string subDir in Directory.GetDirectories(folder))
{
try
{
ApplyAllFiles(subDir, fileAction);
}
catch
{
// swallow, log, whatever
}
}
}
在我的方法中使用这两种方法应该从文档目录及其所有子目录中获取所有文本文件。
在我的方法中,我做了:
ApplyAllFiles(t,ProcessFile(t);
但这是错误的使用方式。我该如何使用这些方法?