Computer
                
              [C#] 파일명과 확장자 추출 예제
                창천(蒼天)
                 2013. 4. 3. 20:26
              
              
            
            
public class 파일명추출
{
    //전체 경로가 입력되었을 때 파일명과 확장자 추출
    public static void Main(string[] args)
    {
        string dir = "c:\\Website\\redPlus\\Images\\test.gif";
        string fullName = String.Empty;
        string name = "";
        string ext = name;
        //전체 파일명 : test.gif
        fullName = dir.Substring(dir.LastIndexOf('\\') + 1);
        //순수 파일명 : test
        name = fullName.Substring(0, fullName.LastIndexOf('.'));
        //확장자 : gif
        ext = fullName.Substring(fullName.LastIndexOf('.'));
        Console.WriteLine(fullName);
        Console.WriteLine((name));
        Console.WriteLine(ext);
    }
}