C#, MONO
유용한 File 접근
gigasound
2021. 8. 9. 12:39
c#에서는 편리하게 파일에 접근하는 방법을 제공합니다. 이 방법은 MONO를 사용해서 linux에서도 동일한 결과를 얻어 줍니다.
현재 디렉터리
System.IO.Directory.GetCurrentDirectory()
파일 존재 여부
if(File.Exists(this.scene_file) == true){...}
경로와 경로의 합성
string db_dir = Path.Combine(System.IO.Directory.GetCurrentDirectory(),"DB");
파일명. 확장자 추출
string filepath = @"D:\다운로드\POP\Survive You.mp3";
string file_fullname = System.IO.Path.GetFileName(filepath); // "Survive You.mp3"
파일명 추출
string filepath = @"D:\다운로드\POP\Survive You.mp3";
string file_name = System.IO.Path.GetFileNameWithoutExtension(filepath); // "Survive You"
확장자 추출
string filepath = @"D:\다운로드\POP\Survive You.mp3";
string file_extension = System.IO.Path.GetExtension(filepath); // ".mp3"
파일 경로 추출
string filepath = @"D:\다운로드\POP\Survive You.mp3";
string file_path = System.IO.Path.GetDirectoryName(filepath); // "D:\다운로드\POP"