반응형
C #의 단일 전체 경로에서 여러 디렉토리를 만드는 방법은 무엇입니까?
전체 경로가있는 경우 : "C:\dir0\dir1\dir2\dir3\dir4\"
모든 디렉토리가 존재하도록 어떻게 구현하는 것이 가장 좋습니까?
BCL에이를위한 방법이 있습니까? 그렇지 않은 경우 가장 우아한 방법은 무엇입니까?
나는 부를 것이다 Directory.CreateDirectory(@"C:\dir0\dir1\dir2\dir3\dir4\")
.
일반적인 믿음과 Directory.CreateDirectory
는 달리 존재하지 않는 상위 디렉토리를 자동으로 작성합니다.
MSDN의 말로Creates all directories and subdirectories as specified by path.
전체 경로가 이미 존재하면 아무 것도 수행하지 않습니다. (예외는 발생하지 않습니다)
완전한 파일 경로에서 디렉토리 작성
private String EvaluatePath(String path){
try
{
String folder = Path.GetDirectoryName(path);
if (!Directory.Exists(folder))
{
// Try to create the directory.
DirectoryInfo di = Directory.CreateDirectory(folder);
}
}
catch (IOException ioex)
{
Console.WriteLine(ioex.Message);
return "";
}
return path;
}
반응형
'development' 카테고리의 다른 글
csv 모듈을 사용하여 csv 파일에서 특정 열을 읽습니까? (0) | 2020.06.13 |
---|---|
org.xml.sax.SAXParseException : 프롤로그에서 컨텐츠를 사용할 수 없습니다 (0) | 2020.06.13 |
금지 된 오류를 던지는 res.sendfile 표현 (0) | 2020.06.13 |
Python 웹 프레임 워크, WSGI 및 CGI가 어떻게 결합 되는가 (0) | 2020.06.13 |
테이블 행 수 (0) | 2020.06.13 |