C# 폴더 안에 파일 목록 구하는 함수입니다.
FindFiles 함수 코딩 정보
public static ArrayList FindFiles(string CurPath, string Pattern, bool IsIncludeSubDir)
{
ArrayList DirAll = new ArrayList();
if (IsIncludeSubDir)
{
GetAllDirectories(CurPath, ref DirAll);
}
else
{
DirAll.Add(new DirectoryInfo(CurPath));
}
//파일의 목록
ArrayList aPathFiles = new ArrayList();
//앞에서 얻어온 모든 DirectoryInfo에 대한 루핑.
foreach (DirectoryInfo d in DirAll)
{
foreach (FileInfo fi in d.GetFiles())
{
aPathFiles.Add(fi.Name);
}
}
return aPathFiles;
}
/// <summary>
/// 지정한 폴더와 하위폴더에 대한 DirectoryInfo 개체를 배열에 저장함.
/// </summary>
/// 루트 경로</param>
/// 각 폴더에 대한 DirectoryInfo를 저장한 배열</param>
private static void GetAllDirectories(string Path, ref ArrayList DirAll)
{
DirectoryInfo di = new DirectoryInfo(Path);
DirAll.Add(di);
foreach (DirectoryInfo d in di.GetDirectories())
{
GetAllDirectories(d.FullName, ref DirAll);
}
}
파일 경로에서 파일명 추출
파일 경로 추출하는 방법을 소개합니다.
// 전체 경로
filesname = "D:\2014XXX.txt";
//전체 파일명 : 2014XXX.txt
fullName = filesname.Substring(filesname.LastIndexOf('\\') + 1);
//순수 파일명 : 2014XXX
name = fullName.Substring(0, fullName.LastIndexOf('.'));
//확장자 : .txt
ext = fullName.Substring(fullName.LastIndexOf('.'));'Programming > C#.NET' 카테고리의 다른 글
| [C#] 오라클 Blob 필드 쓰고 / 읽기 (0) | 2026.06.02 |
|---|---|
| [C#] XML Data 웹페이지 Post 전송 소스 (0) | 2026.05.29 |
| [C#] 제가 주로 사용하는 오라클 DB 처리 클래스(소스) (0) | 2025.12.19 |
| [C#] SerialPort 사용하기 (0) | 2025.12.19 |
| [C#] 기초 - 기본 개념 (0) | 2025.12.01 |