class Lesson
{
public Lesson()
{
// 해당 디렉토리 내부 정보 가져오기
string[] infos = GetDirInfos(@"C:\Windows");
foreach (string info in infos)
{
System.Console.WriteLine(info);
}
}
// 해당 디렉토리의 하위 디렉토리, 파일 정보 가져오기
private string[] GetDirInfos(string dirPath)
{
System.IO.DirectoryInfo infos = new System.IO.DirectoryInfo(dirPath);
System.Collections.Generic.List<string> list = new System.Collections.Generic.List<string>();
foreach (var dir in infos.GetDirectories())
{
list.Add(dir.FullName);
}
foreach (var dir in infos.GetFiles())
{
list.Add(dir.FullName);
}
return list.ToArray();
}
}
- 내용이 간단해서 설명 생략
2023.10.07 - [C#] - [C#] 폴더 (디렉토리) 생성
[C#] 폴더 (디렉토리) 생성
class Lesson { public Lesson() { // 메인디렉토리와 서브디렉토리 생성 CreateDir(@"C:\MainDir\SubDir"); } // 디렉토리 생성 private void CreateDir(string dirPath) { // 해당 경로에 존재하지 않는 디렉토리들 생성 System.IO.
bysik1109.tistory.com
2023.10.07 - [C#] - [C#] 폴더 (디렉토리) 존재 여부 확인
[C#] 폴더 (디렉토리) 존재 여부 확인
class Lesson { public Lesson() { // 디렉토리 존재 여부 확인 bool isExists = IsDirExists(@"C:\MainDir\SubDir"); System.Console.WriteLine(isExists); } // 디렉토리 존재 여부 확인 private bool IsDirExists(string dirPath) { // 존재시 true
bysik1109.tistory.com
2023.10.07 - [C#] - [C#] 파일 생성
[C#] 파일 생성
class Lesson { public Lesson() { // 파일 생성 CreateFile(@"C:\MainDir\File1.txt"); CreateFile(@"C:\MainDir\File2.txt"); } // 파일 생성 private void CreateFile(string filePath) { // 해당 경로가 존재하지 않으면 예외 발생. System.IO.Fi
bysik1109.tistory.com
2023.10.07 - [C#] - [C#] 폴더 (디렉토리) 이동, 이름 변경
[C#] 폴더 (디렉토리) 이동, 이름 변경
class Lesson { public Lesson() { // 디렉토리 생성 CreateDir(@"C:\TestDir"); // 디렉토리 이름 변경 ModifiedDirName(@"C:\TestDir", @"C:\ModifiedDir"); // 디렉토리 생성 CreateDir(@"C:\MainDir"); // 디렉토리 이동 (ModifiedDir 폴더
bysik1109.tistory.com
2023.10.07 - [C#] - [C#] 파일 이동, 이름 변경
[C#] 파일 이동, 이름 변경
class Lesson { public Lesson() { // 디렉토리 생성 CreateDir(@"C:\TestDir"); // 파일 생성 CreateFile(@"C:\TestDir\File1.txt"); // 파일 이름 변경 ModifiedFileName(@"C:\TestDir\File1.txt", @"C:\TestDir\File10.txt"); // 디렉토리 생성 Crea
bysik1109.tistory.com
2023.10.07 - [C#] - [C#] 디렉토리 삭제
[C#] 디렉토리 삭제
class Lesson { public Lesson() { // 디렉토리 생성 CreateDir(@"C:\TestDir"); // 디렉토리 삭제 DeleteDir(@"C:\MainDir1\SubDir", true); } // 디렉토리 생성 private void CreateDir(string dirPath) { // 해당 경로에 존재하지 않는 디
bysik1109.tistory.com
'C#' 카테고리의 다른 글
[C#] 파일 이동, 이름 변경 (0) | 2023.10.07 |
---|---|
[C#] 폴더 (디렉토리) 이동, 이름 변경 (0) | 2023.10.07 |
[C#] 파일 생성 (0) | 2023.10.07 |
[C#] 폴더 (디렉토리) 존재 여부 확인 (0) | 2023.10.07 |
[C#] 폴더 (디렉토리) 생성 (0) | 2023.10.07 |