[C#] 실행경로, 현재 작업 경로 가져오는 방법



 

이번 포스팅에서는 C# 문법 중에서 실행경로, 현재 작업 경로는 가져오는 방법에 대해서 알아보도록 하겠습니다.


작업환경은 WindowsForm 환경에서 작업을 하였고, 간단히 아래와 같이 윈폼 프로젝트를 생성해 주시고, label 컨트롤 4개를 아래와 같이 배치해 주시기 바랍니다.


 



그리고 아래와 같이 코드를 작성해 주시기 바랍니다.

 

Program.cs

 

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

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using System.Windows.Forms;

 

namespace Test

{

    public partial class Form1 : Form

    {

        public Form1()

        {

            InitializeComponent();

 

            string applicationPath = Application.StartupPath;

            string currentJobPath = System.Environment.CurrentDirectory;

 

            label3.Text = "현재 application 존재하는 경로 : " + applicationPath;

            label4.Text = "현재 작업 실행되는 경로 :" + currentJobPath;

            

        }

    }

}

 

Colored by Color Scripter

cs

 

실행 결과




 

간단히 설명을 드리자면,


1.   Application.StartupPath는 현재 application이 존재하는 경로를 알려 주고

2.   System.Environment.CurrentDirectory는 현재 작업이 실행되는 경로를 알려줍니다.


 

감사합니다.^^


728x90

이 글을 공유하기

댓글

Designed by JB FACTORY