2
이 코드를 가지고 :하나의 메소드를 다른 메소드에 매개 변수로 전달하는 방법은 무엇입니까?
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);
을하지만 그것을 사용하는 잘못된 방법입니다 : 내 방법에서
은 내가했다. 방법을 어떻게 사용할 수 있습니까?
pswg 확인하고 내 FOR 루프 변수 textfiles 때문에 더 이상 종료되지 않는다 : for (int i = 0; i
DanielVest
@DanielVest'textfiles'는'ApplyAllFiles'에서 처리되는 모든 파일의 목록으로되어 있습니까? –
p.s.w.g 내 생각 엔 ... textfiles는 string []이 (가) ApplyAllFiles의 모든 파일을 포함하고 텍스트 파일 만 포함해야합니다! – DanielVest