>  기사  >  백엔드 개발  >  C#에서 재귀적으로 파일 나열

C#에서 재귀적으로 파일 나열

WBOY
WBOY앞으로
2023-09-01 08:29:021052검색

在 C# 中递归列出文件

디렉터리의 파일 목록을 얻으려면 C#에서 SearchOptions.AllDirectories를 사용하세요.

먼저 파일을 원하는 디렉터리를 설정하세요. −

string[] myFiles = Directory.GetFiles("D:\New\", "*.*", SearchOption.AllDirectories);

다음은 위에서 언급한 파일을 표시하는 예입니다. 디렉토리 −

Example

using System;
using System.Linq;
using System.IO;
class Program {
   static void Main() {
      string[] myFiles = Directory.GetFiles("D:\New\", "*.*", SearchOption.AllDirectories);
      foreach (string res in myFiles) {
         Console.WriteLine(res);
      }
   }
}

Output

다음은 출력 결과입니다. 폴더의 모든 디렉터리를 나열합니다.

rreee

위 내용은 C#에서 재귀적으로 파일 나열의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

성명:
이 기사는 tutorialspoint.com에서 복제됩니다. 침해가 있는 경우 admin@php.cn으로 문의하시기 바랍니다. 삭제