달성하려는 것은 특정 드라이브 또는 폴더 구조의 모든 파일 목록을 파일을 통해 파싱하여 얻습니다. 또한 권한이 부여되지 않은 예외를 처리하려고합니다. 대부분의 드라이브 및 폴더에서는 코드가 제대로 작동하지만 Windows Drive (C :)와 같은 경우에는 System.StackOverflow 예외가 발생합니다. 문제가 될 수있는 것은 무엇입니까? 더 좋은 방법은 있습니까? ?System.StackOverflow 예외 구조를 통해 구문 분석하는 동안
static void WalkDirectoryTree(System.IO.DirectoryInfo root)
{
System.IO.FileInfo[] files = null;
System.IO.DirectoryInfo[] subDirs = null;
// First, process all the files directly under this folder
try
{
files = root.GetFiles("*.*");
}
// This is thrown if even one of the files requires permissions greater
// than the application provides.
catch (UnauthorizedAccessException e)
{
//eat
}
catch (System.IO.DirectoryNotFoundException e)
{
//eat
}
if (files != null)
{
foreach (System.IO.FileInfo fi in files)
{
Console.WriteLine(fi.FullName);
}
// Now find all the subdirectories under this directory.
subDirs = root.GetDirectories();
foreach (System.IO.DirectoryInfo dirInfo in subDirs)
{
// Resursive call for each subdirectory.
WalkDirectoryTree(dirInfo);
}
}
}
}
디렉토리 트리의 모든 위치에 모든 파일을 나열하려는 경우'root.GetFiles ("*. *", SearchOption.AllDirectories)'를 사용할 수 있습니다. 이렇게하면 재발 할 필요가 없습니다. – porges
@Porges이 방법을 알고 있습니다. 내 애플리케이션에 관리자 권한이 없기 때문에이 프로세스를 수행하고 있습니다. – techno
@techno, 앱에 관리자 권한이없는 경우 재귀 적으로 권한 문제를 해결하려면 어떻게해야합니까? –