블로그 이미지
Every unexpected event is a path to learning for you.

카테고리

분류 전체보기 (2731)
Unity3D (814)
Programming (474)
Server (33)
Unreal (4)
Gamebryo (56)
Tip & Tech (228)
협업 (57)
3DS Max (3)
Game (12)
Utility (136)
Etc (96)
Link (32)
Portfolio (19)
Subject (90)
iOS,OSX (51)
Android (14)
Linux (5)
잉여 프로젝트 (2)
게임이야기 (3)
Memories (20)
Interest (38)
Thinking (38)
한글 (30)
PaperCraft (5)
Animation (408)
Wallpaper (2)
재테크 (18)
Exercise (3)
나만의 맛집 (3)
냥이 (10)
육아 (16)
Total
Today
Yesterday
03-28 00:02

           string strFullPathName;
            string strDirectoryName;
            string strFileName;

 

            OpenFileDialog openFileDialog = new OpenFileDialog();
            openFileDialog.Filter = "실행화일(exe)|*.exe";

 

            if (DialogResult.OK == openFileDialog.ShowDialog())
            {
                strFullPathName = openFileDialog.FileName;

                strDirectoryName = System.IO.Path.GetDirectoryName(strFullPathName);
                strFileName = System.IO.Path.GetFileName(strFullPathName);

 

                MessageBox.Show(strFullPathName);
                MessageBox.Show(strDirectoryName);
                MessageBox.Show(strFileName);

             }

 

화일작업을 하다보면 화일명 또는 디렉토리명만 가져오고 싶은 경우가 있다..

 

이런경우 어떻게 하면될까..?

 

예를들어, C:\Windows\System32\aa.exe  가 있다고 하면

 

Full Path == "C:\Windows\System32\aa.exe"

Directory Name  == > "C:\Windows\System32"

File Name ==> "aa,exe"

 

이런식이다..

 

 

C++에서는 "\"문자찾아서 잘라내기 했던 기억이 있다.

 

하지만, C#에서는 이를 위한 클래스가 있다.

Path.GetDirectoryName()과 Path.GetFileName()이 그것이다..

 

필요할때 쓰면될것 같다. ^^

 

 

 

 

 

또하나.. 시스템 폴더명을 알아보자..

 

시스템폴더는 OS에 따라 Windows\System32가 될수도 있고, Winnt\System32가 될수있다.

 

            string strSysDir = Environment.SystemDirectory.ToString();
            MessageBox.Show(strSysDir);

 

위와같이 Environment.systemDirectory()를 이용하면 된다. ^^


출처 : http://club.paran.com/club/home.do?clubid=eypgworld-bbsView.do?menuno=2509143-clubno=1078741-bbs_no=0PIGp

반응형

'Programming > C#' 카테고리의 다른 글

C# 종료버튼 클릭시 최소화 시키기  (0) 2010.07.20
@" 는 무슨 의미인가요?  (0) 2010.07.20
은양의 프로그래밍 세상  (0) 2010.07.19
이펙티브 C# - 요점 정리  (0) 2010.07.19
Form Show()/Hide()  (0) 2010.07.19
Posted by blueasa
, |