728x90

C# 에서 파일을 저장하고 저장된 파일명을 팝업창으로 보여주고 싶을 때



string filePath = @"C:\Dir\SubDir\file.txt";


string path = Path.GetDirectoryName(fileName);  //
string filename_with_ext = Path.GetFileName(fileName);  //
string filename_without_ext = Path.GetFileNameWithoutExtension(fileName);  //
string ext_only = Path.GetExtension(fileName);  //

DateTime dt = File.GetLastWriteTime(fileName); // 일/


간단 명료하게 함수로 만들어서 사용해도 된다.

private string getFileName(string filePath)
{
     return System.IO.Path.GetFileName(filePath);
}

private string getFilePath(string filePath)
{
     return System.IO.Path.GetDirectoryName(filePath);
}

private string getFileExt(string filePath)
{
     return System.IO.Path.GetExtension(filePath);
}


// 현재 디렉토리 경로 가져오기

string currentPath = System.IO.Directory.GetCurrentDirectory();


// 디렉토리 생성

public static void CreateDirectory(string filePath) 

    if (!Directory.Exists(filePath)) Directory.CreateDirectory(filePath); 


// 파일 삭제

public static void DeleteFile(string filePath) 

    if (File.Exists(filePath)) File.Delete(filePath);   //파일 삭제   
}


'C# > 문법 및 기능' 카테고리의 다른 글

C# 문자열 다루기 StringBuilder  (2) 2015.10.10
C# 문자열 분리 Split  (0) 2015.10.09
C# 변수 선언, 제어문과 자동완성 기능  (2) 2015.09.25
C# enum  (0) 2015.09.23
C# 과 VB 문법 차이  (0) 2015.09.22
블로그 이미지

Link2Me

,