c#文件路径

 

c#判断文件路径是否正确

if (!File.Exists(this.PathTBox.Text))//检测地图路径是否正确
{
MessageBox.Show(" 请修改为正确地图路径再保存");
return;
}

 

 

 

 

 

 

 

 #region 获取指定路径文件夹下子文件夹名称
        /// <summary>
        /// 获取指定路径文件夹下子文件夹名称
        /// </summary>
        /// <param name="sDirPath"></param>
        /// <returns></returns>
        public static List<string> GetChildDirectoryName(string sDirPath)
        {
            List<string> plstDirName = null;
            try
            {
                string sDirName = string.Empty;
                plstDirName = new List<string>();
                DirectoryInfo _direcInfo = new DirectoryInfo(sDirPath);
                DirectoryInfo[] _dirInfo = _direcInfo.GetDirectories();//返回当前目录的子目录
                foreach (DirectoryInfo _directoryInfo in _dirInfo)
                {
                    sDirName = _directoryInfo.Name;
                    if (!plstDirName.Contains(sDirName))
                    {
                        plstDirName.Add(sDirName);
                    }
                }
            }
            catch (Exception )
            {
            }
            return plstDirName;
        }
        #endregion
 #region 获取指定文件夹下文件名称
        /// <summary>
        /// 获取指定文件夹下文件名称
        /// </summary>
        /// <param name="sDirPath"></param>
        /// <returns></returns>
        public static List<string> GetFiles(string sDirPath)
        {
            List<string> plstFileName = null;
            try
            {
                FileInfo[] _fileInfo = null;
                string sFileName = string.Empty;
                plstFileName = new List<string>();

                DirectoryInfo _direcInfo = new DirectoryInfo(sDirPath);
                _fileInfo = _direcInfo.GetFiles();
                foreach (FileInfo _fInfo in _fileInfo)
                {
                    sFileName = _fInfo.Name;
                    if (!plstFileName.Contains(sFileName))
                    {
                        plstFileName.Add(sFileName);
                    }
                }
            }
            catch (Exception )
            {
            }
            return plstFileName;
        }
        #endregion
 #region RGB颜色
        /// <summary>
        /// RGB颜色设置
        /// </summary>
        /// <param name="intR"></param>
        /// <param name="intG"></param>
        /// <param name="intB"></param>
        /// <returns></returns>
        public IRgbColor GetRgbColor(int intR, int intG, int intB)
        {
            IRgbColor pRgbColor = null;
            if (intR < 0 || intR > 255 || intG < 0 || intG > 255 || intB < 0 || intB > 255)
            {
                return pRgbColor;
            }
            pRgbColor = new RgbColor();
            pRgbColor.Red = intR;
            pRgbColor.Green = intG;
            pRgbColor.Blue = intB;
            return pRgbColor;
        }
        #endregion

 

posted @ 2015-11-17 09:48  JaneAi  阅读(365)  评论(0编辑  收藏  举报