당신이하려는 일을 명확히 할 수 있습니까?
마크 (Marc)가 제공 한 예제 코드에서 발견 된 모든 파일에 대해 호출 할 Action을 제공해야합니다. 따라서 해당 액션을 호출하면 해당 파일의 처리가 나타납니다.
폴더 내의 모든 파일과 하위 폴더가 처리 된 시점을 확인하려면 두 번째 작업을 추가하기 위해 코드를 수정해야합니다. 이런 식으로 뭔가 :
using System;
using System.IO;
static class Program
{
static void Main()
{
string path = ""; // TODO
ApplyAllFiles(path, ProcessFile, FolderProcessed);
}
static void ProcessFile(string path) {/* ... */}
static void FolderProcessed(string path) {/* ... */}
static void ApplyAllFiles(string folder, Action<string> fileAction, Action<string> folderProcessed)
{
foreach (string file in Directory.GetFiles(folder))
{
fileAction(file);
}
foreach (string subDir in Directory.GetDirectories(folder))
{
try
{
ApplyAllFiles(subDir, fileAction);
}
catch
{
// swallow, log, whatever
}
}
//**** New action invoked here:
folderProcessed(folder);
}
}
당신이 진행 표시 줄을 원하는 했습니까? 메서드가 폴더 계층을 가로 지르면서 folderDepth 및 증분/감소라는 멤버 변수를 가질 수 있습니다. 메소드를 실행하기 전에'Debug.Write (folderDepth)'를 넣으면 끝낼시기를 더 잘 예측할 수있다. 그냥 내 2 센트 :)이 질문에 대한 답변을 지금 듣고 싶습니다. +1 –
현재 사용자에게 메시지를 출력하기 위해 검색이 완료되면 주요 관심사는 파악하는 것입니다. 변수에 대한 귀하의 제안은 Directory.GetDirectories()와 같은 것을 사용하지 않고, 선택된 폴더에 이미 몇 개의 폴더가 있는지를 알 필요가 있음을 의미합니다. 길이 – denied66