MS 파일 및 경로에 대한 몇 가지 메소드 레코드

4317 단어 서류
하나, 경로 관련
          String path1 = System.IO.Directory.GetCurrentDirectory();

            MessageBox.Show("             :" + path1);



            //

            String path2 = System.AppDomain.CurrentDomain.BaseDirectory;

            MessageBox.Show("        :" + path2);



            //

            String path3 = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase;

            MessageBox.Show("                  :" + path3);



            //                  ,           。

            String path4 = System.Windows.Forms.Application.StartupPath;

            MessageBox.Show("                  ,           :" + path4);



            //                      

            String path5 = System.Windows.Forms.Application.ExecutablePath;

            MessageBox.Show("                      :" + path5);

2 폴더 아래의 모든 파일 이름 가져오기
2.1 DirectoryInfo 사용
               using System.IO;//DirectoryInfo
using System.Windows.Forms; //Application
         DirectoryInfo dzong = new DirectoryInfo(Application.StartupPath); foreach (FileInfo fi in dzong.GetFiles()) { if (fi.Extension.Equals(".doc")) { cbox.Items.Add(fi.Name.Replace(".doc", ""));//cbox combox } }

2.2 Directory 사용
          
            
using System.IO;//Directory
foreach (string f in Directory.GetFiles(Application.StartupPath , "*.doc")) { string[] str = f.Split('\\'); cb_SelectSkin.Items.Add((str[str.Count() - 1]).Replace(".doc", ""));// }

좋은 웹페이지 즐겨찾기