プログラミングのメモ

プログラミングの学び直し備忘録

C#:Tips:ファイルフォルダ

存在確認

        //**********************************************************
        /// <summary>
        /// 存在確認
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        //**********************************************************
        private void btn_存在確認_Click(object sender, EventArgs e)
        {
            string sFile_fp = @"D:\Test\files\Book1.xlsx";
            string sParentPath = System.IO.Path.GetDirectoryName(sFile_fp);

            bool bRes = false;
            
            //## Folder ###############
            bRes = System.IO.Directory.Exists(sParentPath);
            MessageBox.Show(string.Format("File.Directory\n\r{0}\n\r{1}", sParentPath, bRes.ToString()));


            //## File ###############
            bRes = System.IO.File.Exists(sFile_fp);
            MessageBox.Show(string.Format("File.Exists\n\r{0}\n\r{1}", sFile_fp, bRes.ToString()));
        }