对文件和文件夹的操作

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using InsApp.log4;

namespace InsApp.word
{


    /// <summary>
    /// 对文件和文件夹的操作
    /// </summary>
    public class FileClass : CreateCode
    {
        Type type = System.Reflection.MethodBase.GetCurrentMethod().DeclaringType;

        #region 检查文件或者文件目录是否存在,根据参数判断是否创建文件目录[不创建文件]
        /// <summary>
        /// 检查文件||文件目录是否存在, 根据参数判断是否创建文件||文件目录
        /// </summary>
        /// <param name="FilePath">路径</param>
        /// <param name="File_Folder"> file || folder </param>
        /// <param name="Create">true 创建 false 不创建</param>
        /// <returns></returns>
        public bool Check_File(string FilePath,string File_Folder,bool Create)
        {
            if (CheckNullstr(FilePath) == false)        //如果路径为空
            {
                return false;
            }
            else
            {
                try
                {
                    if (File_Folder == "file")                      //如果是判断文件是否存在
                    {
                        if (File.Exists(FilePath) == false)         //文件不存在
                        {
                            return false;
                        }
                        else
                        {
                            return true;
                        }
                    }
                    else                                                //文件夹是否存在
                    {
                        if (Directory.Exists(FilePath) == false)         //文件不存在
                        {
                            if (Create == true)                    
                            {
                                Directory.CreateDirectory(FilePath);        //要创建一个
                                return true;
                            }
                            else
                            {
                                return false;
                            }
                        }
                        else
                        {
                            return true;
                        }
                    }
                }
                catch (Exception ex)
                {
                    return false;
                    LogUtil.ERROR(type, ex.Message);
                }
            }
            return true;
        }
        #endregion
    }
}

posted @ 2007-05-28 15:25  世之云枭  阅读(335)  评论(0编辑  收藏  举报