C#/개발

C# 숨김 폴더(디렉토리) 생성하는 방법

푸코잇 2024. 7. 24. 08:26

C#에서 숨김 폴더(디렉토리)를 생성하는 방법을 배워보자.

static void Main(string[] args)
{
    string dirPath = "HiddenDir";

    // 디렉토리가 존재하지 않으면 생성
    if (!Directory.Exists(dirPath))
    {
        Directory.CreateDirectory(dirPath);
    }

    // 디렉토리 속성을 숨김으로 설정
    DirectoryInfo dirInfo = new DirectoryInfo(dirPath);
    dirInfo.Attributes |= FileAttributes.Hidden;
}

 

디렉토리 경로를 통해 DirectoryInfo 객체를 생성 후 Attributes에 Hidden을 추가해 주면 된다.

 

숨김디렉토리
숨김 폴더(디렉토리) 생성결과