티스토리 뷰

현재 실행 중인 어플리케이션과 같은 폴더에 있는 파일이나, 하위 폴더에 있는 파일의 위치를 지정하고자 한다면, Path 클래스를 사용하면 된다.

아래는 간단한 예제이다.

Application.ExecutablePath 은 현재 실행 중인 어플리케이션의 위치를 반환한다.

Path.GetDirectoryName 은 path에서 폴더 값만 반환한다.

Path.Combine 은 두개의 path를 결합한다.


using System;
using System.IO;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
   public partial class Form1 : Form
   {
       public Form1()
       {
           InitializeComponent();
       }

       private void button1_Click(object sender, EventArgs e)
       {
           textBox1.Text = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "file.txt");
       }
   }
}

공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/06   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30
글 보관함