コード例 #1
0
        /// <summary>
        /// 获取文件夹信息(仅用于B_Label)
        /// </summary>
        public static DataTable GetDirectoryInfoflo(string dir, FsoMethod method)
        {
            PathDeal(ref dir);
            DataRow   row;
            int       num;
            DataTable table = GetDTFormat3();

            if (method != FsoMethod.File)
            {
                for (num = 0; num < getDirs(dir).Length; num++)
                {
                    row = table.NewRow();
                    DirectoryInfo d = new DirectoryInfo(getDirs(dir)[num]);
                    //long[] numArray = DirInfo(d);
                    row[0] = d.Name;
                    row[1] = 1;
                    row[2] = 0;
                    row[3] = "";
                    row[4] = d.CreationTime;
                    row[5] = d.LastWriteTime;
                    table.Rows.Add(row);
                }
            }
            return(table);
        }
コード例 #2
0
 /// <summary>
 /// 删除操作
 /// <param name="file">file待删除的文件</param>
 /// <param name="method">method 操作对象FsoMethod的枚举类型Folder文件夹 File文件</param>
 /// <param name="delSelf">删除文件夹时,是否删除本身</param>
 /// </summary>
 public static void Delete(string file, FsoMethod method, bool delSelf = true)
 {
     if ((method == FsoMethod.File) && File.Exists(file))
     {
         File.Delete(file);
     }
     if ((method == FsoMethod.Folder) && Directory.Exists(file))
     {
         string curPath = file;
         try
         {
             DirectoryInfo   dir    = new DirectoryInfo(file);
             DirectoryInfo[] childs = dir.GetDirectories();
             foreach (DirectoryInfo child in childs)
             {
                 curPath = child.FullName;
                 child.Delete(true);
             }
             if (delSelf)
             {
                 dir.Delete(true);
             }
         }
         catch (Exception ex) { throw new Exception("[" + curPath + "]" + ex.Message); }
     }
 }
コード例 #3
0
 /// <summary>
 /// 判断是否存在
 /// </summary>
 /// <param name="file">物理路径</param>
 /// <param name="method"></param>
 /// <returns></returns>
 public static Boolean IsExist(string file, FsoMethod method)
 {
     if (method == FsoMethod.File)
     {
         return(System.IO.File.Exists(file));
     }
     return((method == FsoMethod.Folder) && Directory.Exists(file));
 }
コード例 #4
0
 /// <summary>
 /// 操作对象是否存在
 /// </summary>
 /// <param name="file"></param>
 /// <param name="method"></param>
 /// <returns></returns>
 public static bool IsExists(string file, FsoMethod method)
 {
     if (method == FsoMethod.File)
     {
         return(File.Exists(file));
     }
     return((method == FsoMethod.Folder) && Directory.Exists(file));
 }
コード例 #5
0
        /// <summary>
        /// 获取文件夹信息[推荐]
        /// </summary>
        /// <dir>目录物理路径</dir>
        public static DataTable GetDirectoryInfos(string dir, FsoMethod method)
        {
            string vdir = function.PToV(dir);

            PathDeal(ref dir);
            //rar,aspx,asp,php,html,htm,txt,xml,config
            DataRow          row;
            int              num;
            DataTable        table = GetDTFormat();
            FileSystemObject fs    = new FileSystemObject();

            if (method != FsoMethod.File)
            {
                for (num = 0; num < getDirs(dir).Length; num++)
                {
                    row = table.NewRow();
                    DirectoryInfo info = new DirectoryInfo(getDirs(dir)[num]);
                    //long[] numArray = DirInfo(d);
                    row[0] = info.Name;
                    row[1] = 1;
                    //long size = getDirectorySize(@"" + d.FullName + "");//文件夹不统计大小,节省资源
                    //row["ExSize"] = ((size / 1024) + (size % 1024 > 1 ? 1 : 0)).ToString() + "KB";
                    row[3]          = "";
                    row[4]          = info.CreationTime;
                    row[5]          = info.LastWriteTime;
                    row["ExName"]   = "FileFolder";
                    row["ExType"]   = "文件夹";
                    row["FullPath"] = info.FullName;
                    row["VPath"]    = vdir + info.Name;
                    table.Rows.Add(row);
                }
            }
            if (method != FsoMethod.Folder)
            {
                for (num = 0; num < getFiles(dir).Length; num++)
                {
                    row = table.NewRow();
                    FileInfo info = new FileInfo(getFiles(dir)[num]);
                    row[0]          = info.Name;
                    row[1]          = 2;
                    row[2]          = info.Length;
                    row[3]          = info.Extension.Replace(".", "");
                    row[4]          = info.CreationTime;
                    row[5]          = info.LastWriteTime;
                    row["ExSize"]   = ((info.Length / 1024) + (info.Length % 1024 > 1 ? 1 : 0)).ToString() + "KB";
                    row["ExName"]   = info.Extension;
                    row["ExType"]   = "";// fs.GetTypeName(getFiles(dir)[num]);
                    row["FullPath"] = info.FullName;
                    row["VPath"]    = vdir + info.Name;
                    table.Rows.Add(row);
                }
            }
            for (int i = 0; i < table.Rows.Count; i++)
            {
                table.Rows[i]["ID"] = (i + 1);
            }
            return(table);
        }
コード例 #6
0
 public static void Move(string oldFile, string newFile, FsoMethod method)
 {
     if (method == FsoMethod.File)
     {
         File.Move(oldFile, newFile);
     }
     if (method == FsoMethod.Folder)
     {
         Directory.Move(oldFile, newFile);
     }
 }
コード例 #7
0
 public FolderInfo()
 {
     this.m_name          = "";
     this.m_fullName      = "";
     this.m_contentType   = "";
     this.m_type          = 0;
     this.m_fsoType       = FsoMethod.Folder;
     this.m_path          = "";
     this.m_lastWriteTime = DateTime.Now;
     this.m_length        = 0L;
 }
コード例 #8
0
 public static void Delete(string file, FsoMethod method)
 {
     if ((method == FsoMethod.File) && File.Exists(file))
     {
         File.Delete(file);
     }
     if ((method == FsoMethod.Folder) && Directory.Exists(file))
     {
         Directory.Delete(file, true);
     }
 }
コード例 #9
0
        private static DataTable GetDirectoryList(DirectoryInfo directoryInfo, FsoMethod method)
        {
            DataTable dataTable = new DataTable();

            dataTable.Columns.Add("Name");
            dataTable.Columns.Add("FullName");
            dataTable.Columns.Add("ContentType");
            dataTable.Columns.Add("Type");
            dataTable.Columns.Add("Path");
            dataTable.Columns.Add("LastWriteTime");
            dataTable.Columns.Add("Length");
            DirectoryInfo[] directories = directoryInfo.GetDirectories();
            DirectoryInfo[] array       = directories;
            for (int i = 0; i < array.Length; i++)
            {
                DirectoryInfo directoryInfo2 = array[i];
                if (method == FsoMethod.File)
                {
                    dataTable = FileManager.Merge(dataTable, FileManager.GetDirectoryList(directoryInfo2, method));
                }
                else
                {
                    DataRow dataRow = dataTable.NewRow();
                    dataRow[0] = directoryInfo2.Name;
                    dataRow[1] = directoryInfo2.FullName;
                    dataRow[2] = "";
                    dataRow[3] = 0;
                    dataRow[4] = directoryInfo2.FullName.Replace(directoryInfo2.Name, "");
                    dataRow[5] = directoryInfo2.LastWriteTime;
                    dataRow[6] = "";
                    dataTable.Rows.Add(dataRow);
                    dataTable = FileManager.Merge(dataTable, FileManager.GetDirectoryList(directoryInfo2, method));
                }
            }
            if (method != FsoMethod.Folder)
            {
                FileInfo[] files  = directoryInfo.GetFiles();
                FileInfo[] array2 = files;
                for (int j = 0; j < array2.Length; j++)
                {
                    FileInfo fileInfo = array2[j];
                    DataRow  dataRow  = dataTable.NewRow();
                    dataRow[0] = fileInfo.Name;
                    dataRow[1] = fileInfo.FullName;
                    dataRow[2] = fileInfo.Extension.Replace(".", "");
                    dataRow[3] = 1;
                    dataRow[4] = fileInfo.DirectoryName + "\\";
                    dataRow[5] = fileInfo.LastWriteTime;
                    dataRow[6] = fileInfo.Length;
                    dataTable.Rows.Add(dataRow);
                }
            }
            return(dataTable);
        }
コード例 #10
0
 public static DataTable GetDirectoryList(string directory, FsoMethod method)
 {
     try
     {
         DirectoryInfo directoryInfo = new DirectoryInfo(directory);
         return(GetDirectoryList(directoryInfo, method));
     }
     catch (Exception ex)
     {
         throw new Exception(ex.ToString());
     }
 }
コード例 #11
0
        // 获取文件夹信息
        private static DataTable GetDirectoryAllInfo(DirectoryInfo d, FsoMethod method)
        {
            DataRow   row;
            DataTable parent = new DataTable();

            parent.Columns.Add("name");
            parent.Columns.Add("rname");
            parent.Columns.Add("content_type");
            parent.Columns.Add("type");
            parent.Columns.Add("path");
            parent.Columns.Add("creatime", typeof(DateTime));
            parent.Columns.Add("size", typeof(int));
            DirectoryInfo[] directories = d.GetDirectories();
            foreach (DirectoryInfo info in directories)
            {
                if (method == FsoMethod.File)
                {
                    parent = CopyDT(parent, GetDirectoryAllInfo(info, method));
                }
                else
                {
                    row    = parent.NewRow();
                    row[0] = info.Name;
                    row[1] = info.FullName;
                    row[2] = "";
                    row[3] = 1;
                    row[4] = info.FullName.Replace(info.Name, "");
                    row[5] = info.CreationTime;
                    row[6] = 0;
                    parent.Rows.Add(row);
                    parent = CopyDT(parent, GetDirectoryAllInfo(info, method));
                }
            }
            if (method != FsoMethod.Folder)
            {
                FileInfo[] files = d.GetFiles();
                foreach (FileInfo info2 in files)
                {
                    row    = parent.NewRow();
                    row[0] = info2.Name;
                    row[1] = info2.FullName;
                    row[2] = info2.Extension.Replace(".", "");
                    row[3] = 2;
                    row[4] = info2.DirectoryName + @"\";
                    row[5] = info2.CreationTime;
                    row[6] = info2.Length;

                    parent.Rows.Add(row);
                }
            }
            return(parent);
        }
コード例 #12
0
        private static DataTable GetDirectoryList(DirectoryInfo directoryInfo, FsoMethod method)
        {
            DataTable dataTable = new DataTable();

            dataTable.Columns.Add("Name");
            dataTable.Columns.Add("FullName");
            dataTable.Columns.Add("ContentType");
            dataTable.Columns.Add("Type");
            dataTable.Columns.Add("Path");
            dataTable.Columns.Add("LastWriteTime");
            dataTable.Columns.Add("Length");
            DirectoryInfo[] directories = directoryInfo.GetDirectories();
            DirectoryInfo[] array       = directories;
            foreach (DirectoryInfo directoryInfo2 in array)
            {
                if (method == FsoMethod.File)
                {
                    dataTable = Merge(dataTable, GetDirectoryList(directoryInfo2, method));
                }
                else
                {
                    DataRow dataRow = dataTable.NewRow();
                    dataRow[0] = directoryInfo2.Name;
                    dataRow[1] = directoryInfo2.FullName;
                    dataRow[2] = "";
                    dataRow[3] = 0;
                    dataRow[4] = directoryInfo2.FullName.Replace(directoryInfo2.Name, "");
                    dataRow[5] = directoryInfo2.LastWriteTime;
                    dataRow[6] = "";
                    dataTable.Rows.Add(dataRow);
                    dataTable = Merge(dataTable, GetDirectoryList(directoryInfo2, method));
                }
            }
            if (method != 0)
            {
                FileInfo[] files  = directoryInfo.GetFiles();
                FileInfo[] array2 = files;
                foreach (FileInfo fileInfo in array2)
                {
                    DataRow dataRow = dataTable.NewRow();
                    dataRow[0] = fileInfo.Name;
                    dataRow[1] = fileInfo.FullName;
                    dataRow[2] = fileInfo.Extension.Replace(".", "");
                    dataRow[3] = 1;
                    dataRow[4] = fileInfo.DirectoryName + "\\";
                    dataRow[5] = fileInfo.LastWriteTime;
                    dataRow[6] = fileInfo.Length;
                    dataTable.Rows.Add(dataRow);
                }
            }
            return(dataTable);
        }
コード例 #13
0
        /// <summary>
        /// 获取指定目录下的所有目录及其文件信息
        /// </summary>
        /// <param name="directoryInfo">目录</param>
        /// <param name="method">获取方式</param>
        /// <returns>返回目录文件列表的DataTable对象</returns>
        private static DataTable GetDirectoryList(DirectoryInfo directoryInfo, FsoMethod method)
        {
            DataRow   row;
            DataTable parent = new DataTable();

            parent.Columns.Add("Name");
            parent.Columns.Add("FullName");
            parent.Columns.Add("ContentType");
            parent.Columns.Add("Type");
            parent.Columns.Add("Path");
            parent.Columns.Add("LastWriteTime");
            parent.Columns.Add("Length");
            DirectoryInfo[] directories = directoryInfo.GetDirectories();
            foreach (DirectoryInfo info in directories)
            {
                if (method == FsoMethod.File)
                {
                    parent = Merge(parent, GetDirectoryList(info, method));
                }
                else
                {
                    row    = parent.NewRow();
                    row[0] = info.Name;
                    row[1] = info.FullName;
                    row[2] = "";
                    row[3] = 0;
                    row[4] = info.FullName.Replace(info.Name, "");
                    row[5] = info.LastWriteTime;
                    row[6] = "";
                    parent.Rows.Add(row);
                    parent = Merge(parent, GetDirectoryList(info, method));
                }
            }
            if (method != FsoMethod.Folder)
            {
                FileInfo[] files = directoryInfo.GetFiles();
                foreach (FileInfo info2 in files)
                {
                    row    = parent.NewRow();
                    row[0] = info2.Name;
                    row[1] = info2.FullName;
                    row[2] = info2.Extension.Replace(".", "");
                    row[3] = 1;
                    row[4] = info2.DirectoryName + @"\";
                    row[5] = info2.LastWriteTime;
                    row[6] = info2.Length;
                    parent.Rows.Add(row);
                }
            }
            return(parent);
        }
コード例 #14
0
        public static DataTable GetDirectoryAllInfos(string dir, FsoMethod method)
        {
            DataTable directoryAllInfo;

            try
            {
                DirectoryInfo d = new DirectoryInfo(dir);
                directoryAllInfo = GetDirectoryAllInfo(d, method);
            }
            catch (Exception exception)
            {
                throw new FileNotFoundException(exception.ToString());
            }
            return(directoryAllInfo);
        }
コード例 #15
0
        /// <summary>
        /// 获取目录列表
        /// </summary>
        /// <param name="directory">路径</param>
        /// <param name="method">类型</param>
        /// <returns></returns>
        public static DataTable GetDirectoryList(string directory, FsoMethod method)
        {
            DataTable directoryList;

            try
            {
                DirectoryInfo directoryInfo = new DirectoryInfo(directory);
                directoryList = FileManager.GetDirectoryList(directoryInfo, method);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.ToString());
            }
            return(directoryList);
        }
コード例 #16
0
        /// <summary>
        /// 获取指定目录的目录信息
        /// </summary>
        /// <param name="directory">目录</param>
        /// <param name="method">获取方式</param>
        /// <returns>返回目录文件列表的DataTable对象</returns>
        public static DataTable GetDirectoryFilesList(string directory, FsoMethod method)
        {
            DataRow   row;
            int       num;
            DataTable table = new DataTable();

            table.Columns.Add("Name");
            table.Columns.Add("FullName");
            table.Columns.Add("ContentType");
            table.Columns.Add("Type");
            table.Columns.Add("Path");
            table.Columns.Add("LastWriteTime");
            table.Columns.Add("Length");
            if (method != FsoMethod.File)
            {
                for (num = 0; num < GetDirectories(directory).Length; num++)
                {
                    row = table.NewRow();
                    DirectoryInfo info = new DirectoryInfo(GetDirectories(directory)[num]);
                    row[0] = info.Name;
                    row[1] = info.FullName;
                    row[2] = "";
                    row[3] = 0;
                    row[4] = info.FullName.Replace(info.Name, "");
                    row[5] = info.LastWriteTime;
                    row[6] = "";
                    table.Rows.Add(row);
                }
            }
            if (method != FsoMethod.Folder)
            {
                for (num = 0; num < GetFiles(directory).Length; num++)
                {
                    row = table.NewRow();
                    FileInfo info2 = new FileInfo(GetFiles(directory)[num]);
                    row[0] = info2.Name;
                    row[1] = info2.FullName;
                    row[2] = info2.Extension.Replace(".", "");
                    row[3] = 1;
                    row[4] = info2.DirectoryName + @"\";
                    row[5] = info2.LastWriteTime;
                    row[6] = info2.Length;
                    table.Rows.Add(row);
                }
            }
            return(table);
        }
コード例 #17
0
        public static DataTable GetDirectoryInfos(string dir, FsoMethod method)
        {
            DataRow   row;
            DataTable table = new DataTable();

            table.Locale = CultureInfo.CurrentCulture;
            table.Columns.Add("name", typeof(string));
            table.Columns.Add("type");
            table.Columns.Add("size", typeof(long));
            table.Columns.Add("content_type");
            table.Columns.Add("createTime", typeof(DateTime));
            table.Columns.Add("lastWriteTime", typeof(DateTime));
            if (method != FsoMethod.File)
            {
                for (int i = 0; i < getDirs(dir).Length; i++)
                {
                    row = table.NewRow();
                    DirectoryInfo d        = new DirectoryInfo(getDirs(dir)[i]);
                    long[]        numArray = DirInfo(d);
                    row[0] = d.Name;
                    row[1] = 1;
                    row[2] = numArray[0];
                    row[3] = "";
                    row[4] = d.CreationTime;
                    row[5] = d.LastWriteTime;
                    table.Rows.Add(row);
                }
            }
            if (method != FsoMethod.Folder)
            {
                for (int j = 0; j < getFiles(dir).Length; j++)
                {
                    row = table.NewRow();
                    FileInfo info2 = new FileInfo(getFiles(dir)[j]);
                    row[0] = info2.Name;
                    row[1] = 2;
                    row[2] = info2.Length;
                    row[3] = info2.Extension.Replace(".", "");
                    row[4] = info2.CreationTime;
                    row[5] = info2.LastWriteTime;
                    table.Rows.Add(row);
                }
            }
            return(table);
        }
コード例 #18
0
        /// <summary>
        /// 获取目录文件列表
        /// </summary>
        /// <param name="directory">路径</param>
        /// <param name="method">类型</param>
        /// <returns></returns>
        public static DataTable GetDirectoryFilesList(string directory, FsoMethod method)
        {
            DataTable dataTable = new DataTable();

            dataTable.Columns.Add("Name");
            dataTable.Columns.Add("FullName");
            dataTable.Columns.Add("ContentType");
            dataTable.Columns.Add("Type");
            dataTable.Columns.Add("Path");
            dataTable.Columns.Add("LastWriteTime");
            dataTable.Columns.Add("Length");
            if (method != FsoMethod.File)
            {
                for (int i = 0; i < FileManager.GetDirectories(directory).Length; i++)
                {
                    DataRow       dataRow       = dataTable.NewRow();
                    DirectoryInfo directoryInfo = new DirectoryInfo(FileManager.GetDirectories(directory)[i]);
                    dataRow[0] = directoryInfo.Name;
                    dataRow[1] = directoryInfo.FullName;
                    dataRow[2] = "";
                    dataRow[3] = 0;
                    dataRow[4] = directoryInfo.FullName.Replace(directoryInfo.Name, "");
                    dataRow[5] = directoryInfo.LastWriteTime;
                    dataRow[6] = "";
                    dataTable.Rows.Add(dataRow);
                }
            }
            if (method != FsoMethod.Folder)
            {
                for (int i = 0; i < FileManager.GetFiles(directory).Length; i++)
                {
                    DataRow  dataRow  = dataTable.NewRow();
                    FileInfo fileInfo = new FileInfo(FileManager.GetFiles(directory)[i]);
                    dataRow[0] = fileInfo.Name;
                    dataRow[1] = fileInfo.FullName;
                    dataRow[2] = fileInfo.Extension.Replace(".", "");
                    dataRow[3] = 1;
                    dataRow[4] = fileInfo.DirectoryName + "\\";
                    dataRow[5] = fileInfo.LastWriteTime;
                    dataRow[6] = fileInfo.Length;
                    dataTable.Rows.Add(dataRow);
                }
            }
            return(dataTable);
        }
コード例 #19
0
 /// <summary>
 /// 创建文件
 /// </summary>
 /// <param name="file">路径</param>
 /// <param name="method">文件类型</param>
 public static void Create(string file, FsoMethod method)
 {
     try
     {
         if (method == FsoMethod.File)
         {
             FileManager.WriteFile(file, "");
         }
         else if (method == FsoMethod.Folder)
         {
             Directory.CreateDirectory(file);
         }
     }
     catch (Exception ex)
     {
         throw new Exception(ex.ToString());
     }
 }
コード例 #20
0
 /// <summary>
 /// 删除
 /// </summary>
 /// <param name="file">路径</param>
 /// <param name="method">文件类型</param>
 public static void Delete(string file, FsoMethod method)
 {
     try
     {
         if (method == FsoMethod.File)
         {
             File.Delete(file);
         }
         if (method == FsoMethod.Folder)
         {
             Directory.Delete(file, true);
         }
     }
     catch (Exception ex)
     {
         throw new Exception(ex.ToString());
     }
 }
コード例 #21
0
 public static void Create(string file, FsoMethod method)
 {
     try
     {
         if (method == FsoMethod.File)
         {
             WriteFile(file, "");
         }
         else if (method == FsoMethod.Folder)
         {
             Directory.CreateDirectory(file);
         }
     }
     catch
     {
         throw new UnauthorizedAccessException("没有权限!");
     }
 }
コード例 #22
0
 /// <summary>
 /// 移动
 /// </summary>
 /// <param name="srcFile">原路径</param>
 /// <param name="desFile">现路径</param>
 /// <param name="method">类型</param>
 public static void Move(string srcFile, string desFile, FsoMethod method)
 {
     try
     {
         if (method == FsoMethod.File)
         {
             File.Move(srcFile, desFile);
         }
         if (method == FsoMethod.Folder)
         {
             Directory.Move(srcFile, desFile);
         }
     }
     catch (Exception ex)
     {
         throw new Exception(ex.ToString());
     }
 }
コード例 #23
0
        public static List <DirectoryInfos> GetDirectoryInfos(string dir, FsoMethod method)
        {
            var list = new List <DirectoryInfos>();

            dir = FileHelper.MapPath(dir);
            if (method != FsoMethod.File)
            {
                for (int i = 0; i < Directory.GetDirectories(dir).Length; i++)
                {
                    var           model    = new DirectoryInfos();
                    DirectoryInfo d        = new DirectoryInfo(Directory.GetDirectories(dir)[i]);
                    Int64[]       numArray = DirInfo(d);
                    model.name          = d.Name;
                    model.type          = 1;
                    model.size          = numArray[0];
                    model.content_type  = string.Empty;
                    model.createTime    = d.CreationTime;
                    model.lastWriteTime = d.LastWriteTime;
                    model.path          = d.Name;
                    model.Id            = i + 1;
                    list.Add(model);
                }
            }
            if (method != FsoMethod.Folder)
            {
                for (int j = 0; j < Directory.GetFiles(dir).Length; j++)
                {
                    var model = new DirectoryInfos();
                    var info2 = new System.IO.FileInfo(Directory.GetFiles(dir)[j]);
                    model.name          = info2.Name;
                    model.type          = 2;
                    model.size          = info2.Length;
                    model.content_type  = info2.Extension.Replace(".", string.Empty);
                    model.createTime    = info2.CreationTime;
                    model.lastWriteTime = info2.LastWriteTime;
                    model.path          = info2.Name;
                    model.Id            = j + 1;
                    list.Add(model);
                }
            }
            return(list);
        }
コード例 #24
0
 /// <summary>
 /// 创建文件
 /// <param name="file">文件名</param>
 /// <param name="method">创建方式 Folder文件夹 File文件</param>
 /// </summary>
 public static void Create(string file, FsoMethod method)
 {
     PathDeal(ref file);
     FNameCheck(file);
     try
     {
         if (method == FsoMethod.File)
         {
             WriteFile(file, "");
         }
         else if (method == FsoMethod.Folder)
         {
             Directory.CreateDirectory(file);
         }
     }
     catch (Exception err)
     {
         throw new UnauthorizedAccessException("无法创建文件," + err.ToString());
     }
 }
コード例 #25
0
        public static void Create(string file, FsoMethod method)
        {
            try
            {
                switch (method)
                {
                case FsoMethod.File:
                    WriteFile(file, "");
                    break;

                case FsoMethod.Folder:
                    Directory.CreateDirectory(file);
                    break;
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.ToString());
            }
        }
コード例 #26
0
        private static List <DirectoryAllInfo> GetDirectoryAllInfo(DirectoryInfo d, FsoMethod method)
        {
            var list = new List <DirectoryAllInfo>();

            foreach (DirectoryInfo info in d.GetDirectories())
            {
                if (method == FsoMethod.File)
                {
                    list = CopyDT(list, GetDirectoryAllInfo(info, method));
                }
                else
                {
                    var model = new DirectoryAllInfo();
                    model.name         = info.Name;
                    model.rname        = info.FullName;
                    model.content_type = string.Empty;
                    model.type         = 1;
                    model.path         = info.FullName.Replace(info.Name, string.Empty);
                    model.creatime     = info.CreationTime;
                    model.size         = 0;
                    list.Add(model);
                    list = CopyDT(list, GetDirectoryAllInfo(info, method));
                }
            }
            if (method != FsoMethod.Folder)
            {
                foreach (var info2 in d.GetFiles())
                {
                    var model = new DirectoryAllInfo();
                    model.name         = info2.Name;
                    model.rname        = info2.FullName;
                    model.content_type = info2.Extension.Replace(".", string.Empty);
                    model.type         = 2;
                    model.path         = info2.DirectoryName + @"\";
                    model.creatime     = info2.CreationTime;
                    model.size         = info2.Length;
                    list.Add(model);
                }
            }
            return(list);
        }
コード例 #27
0
        public static bool Exists(string file, FsoMethod method)
        {
            try
            {
                switch (method)
                {
                case FsoMethod.File:
                    return(File.Exists(file));

                case FsoMethod.Folder:
                    return(Directory.Exists(file));

                default:
                    return(false);
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.ToString());
            }
        }
コード例 #28
0
        /// <summary>
        /// 获取文件夹信息
        /// </summary>
        public static DataTable GetDirectoryInfosmall(string dir, FsoMethod method)
        {
            PathDeal(ref dir);
            DataRow   row;
            int       num;
            DataTable table = GetDTFormat3();

            if (method != FsoMethod.File)
            {
                for (num = 0; num < getDirs(dir).Length; num++)
                {
                    row = table.NewRow();
                    DirectoryInfo d = new DirectoryInfo(getDirs(dir)[num]);

                    row[0] = d.Name;
                    row[1] = 1;
                    row[2] = 0;
                    row[3] = "";
                    row[4] = d.CreationTime;
                    row[5] = d.LastWriteTime;
                    table.Rows.Add(row);
                }
            }
            if (method != FsoMethod.Folder)
            {
                for (num = 0; num < getFiles(dir).Length; num++)
                {
                    row = table.NewRow();
                    FileInfo info2 = new FileInfo(getFiles(dir)[num]);
                    row[0] = info2.Name;
                    row[1] = 2;
                    row[2] = info2.Length;
                    row[3] = info2.Extension.Replace(".", "");
                    row[4] = info2.CreationTime;
                    row[5] = info2.LastWriteTime;
                    table.Rows.Add(row);
                }
            }
            return(table);
        }
コード例 #29
0
        /// <summary>
        /// 判断文件或文件夹是否存在,存在为 true,否则为 false;
        /// </summary>
        /// <param name="file">指定文件及其路径</param>
        /// <param name="method">判断方式</param>
        /// <returns></returns>
        public static bool Exists(string file, FsoMethod method)
        {
            bool flag;

            try
            {
                if (method == FsoMethod.File)
                {
                    return(File.Exists(file));
                }
                if (method == FsoMethod.Folder)
                {
                    return(Directory.Exists(file));
                }
                flag = false;
            }
            catch (Exception exception)
            {
                throw new Exception(exception.ToString());
            }
            return(flag);
        }
コード例 #30
0
ファイル: Log.cs プロジェクト: dendi6666/demo-doudizhu
 public static bool fileIsExist(string file, FsoMethod method)
 {
     try
     {
         if (method == FsoMethod.File)
         {
             return(File.Exists(file));
         }
         else if (method == FsoMethod.Folder)
         {
             return(Directory.Exists(file));
         }
         else
         {
             return(false);
         }
     }
     catch (Exception exc)
     {
         throw new Exception(exc.ToString());
     }
 }
コード例 #31
0
ファイル: Log.cs プロジェクト: kinghuc/521266750_qq_com
 public static  bool fileIsExist(string file, FsoMethod method)
 {
     try
     {
         if (method == FsoMethod.File)
         {
             return File.Exists(file);
         }
         else if (method == FsoMethod.Folder)
         {
             return Directory.Exists(file);
         }
         else
         {
             return false;
         }
     }
     catch (Exception exc)
     {
         throw new Exception(exc.ToString());
     }
 }
コード例 #32
0
ファイル: FileSystemObject.cs プロジェクト: caisimongit/cms-1
 /// <summary>
 /// 获取文件夹信息
 /// </summary>
 private static DataTable GetDirectoryAllInfo(DirectoryInfo d, FsoMethod method)
 {
     DataRow row;
     DataTable parent = new DataTable();
     parent.Columns.Add("name");
     parent.Columns.Add("rname");
     parent.Columns.Add("content_type");
     parent.Columns.Add("type");
     parent.Columns.Add("path");
     parent.Columns.Add("creatime", typeof(DateTime));
     parent.Columns.Add("size", typeof(int));
     DirectoryInfo[] directories = d.GetDirectories();
     foreach (DirectoryInfo info in directories)
     {
         if (method == FsoMethod.File)
         {
             parent = CopyDT(parent, GetDirectoryAllInfo(info, method));
         }
         else
         {
             row = parent.NewRow();
             row[0] = info.Name;
             row[1] = info.FullName;
             row[2] = "";
             row[3] = 1;
             row[4] = info.FullName.Replace(info.Name, "");
             row[5] = info.CreationTime;
             row[6] = "";
             parent.Rows.Add(row);
             parent = CopyDT(parent, GetDirectoryAllInfo(info, method));
         }
     }
     if (method != FsoMethod.Folder)
     {
         FileInfo[] files = d.GetFiles();
         foreach (FileInfo info2 in files)
         {
             row = parent.NewRow();
             row[0] = info2.Name;
             row[1] = info2.FullName;
             row[2] = info2.Extension.Replace(".", "");
             row[3] = 2;
             row[4] = info2.DirectoryName + @"\";
             row[5] = info2.CreationTime;
             row[6] = info2.Length;
             parent.Rows.Add(row);
         }
     }
     return parent;
 }
コード例 #33
0
ファイル: FileSystemObject.cs プロジェクト: caisimongit/cms-1
 /// <summary>
 /// 创建文件
 /// <param name="file">文件名</param>
 /// <param name="method">创建方式 Folder文件夹 File文件</param>
 /// </summary>
 public static void Create(string file, FsoMethod method)
 {
     try
     {
         if (method == FsoMethod.File)
         {
             WriteFile(file, "");
         }
         else if (method == FsoMethod.Folder)
         {
             Directory.CreateDirectory(file);
         }
     }
     catch
     {
         throw new UnauthorizedAccessException("无法创建文件");
     }
 }
コード例 #34
0
ファイル: FileSystemObject.cs プロジェクト: caisimongit/cms-1
 /// <summary>
 /// 删除操作
 /// <param name="file">file待删除的文件</param>
 /// <param name="method">method 操作对象FsoMethod的枚举类型Folder文件夹 File文件</param>
 /// </summary>
 public static void Delete(string file, FsoMethod method)
 {
     if ((method == FsoMethod.File) && File.Exists(file))
     {
         File.Delete(file);
     }
     if ((method == FsoMethod.Folder) && Directory.Exists(file))
     {
         Directory.Delete(file, true);
     }
 }
コード例 #35
0
ファイル: FileSystemObject.cs プロジェクト: caisimongit/cms-1
 /// <summary>
 /// 获取文件夹信息
 /// </summary>
 public static DataTable GetDirectoryAllInfos(string dir, FsoMethod method)
 {
     DataTable directoryAllInfo;
     try
     {
         DirectoryInfo d = new DirectoryInfo(dir);
         directoryAllInfo = GetDirectoryAllInfo(d, method);
     }
     catch (Exception exception)
     {
         throw new FileNotFoundException(exception.ToString());
     }
     return directoryAllInfo;
 }
コード例 #36
0
ファイル: FileSystemObject.cs プロジェクト: caisimongit/cms-1
 /// <summary>
 /// 获取文件夹信息
 /// </summary>
 public static DataTable GetDirectoryInfos(string dir, FsoMethod method)
 {
     DataRow row;
     int num;
     DataTable table = new DataTable();
     table.Columns.Add("name", typeof(string));
     table.Columns.Add("type");
     table.Columns.Add("size", typeof(int));
     table.Columns.Add("content_type");
     table.Columns.Add("createTime", typeof(DateTime));
     table.Columns.Add("lastWriteTime", typeof(DateTime));
     if (method != FsoMethod.File)
     {
         for (num = 0; num < getDirs(dir).Length; num++)
         {
             row = table.NewRow();
             DirectoryInfo d = new DirectoryInfo(getDirs(dir)[num]);
             long[] numArray = DirInfo(d);
             row[0] = d.Name;
             row[1] = 1;
             row[2] = numArray[0];
             row[3] = "";
             row[4] = d.CreationTime;
             row[5] = d.LastWriteTime;
             table.Rows.Add(row);
         }
     }
     if (method != FsoMethod.Folder)
     {
         for (num = 0; num < getFiles(dir).Length; num++)
         {
             row = table.NewRow();
             FileInfo info2 = new FileInfo(getFiles(dir)[num]);
             row[0] = info2.Name;
             row[1] = 2;
             row[2] = info2.Length;
             row[3] = info2.Extension.Replace(".", "");
             row[4] = info2.CreationTime;
             row[5] = info2.LastWriteTime;
             table.Rows.Add(row);
         }
     }
     return table;
 }
コード例 #37
0
ファイル: FileSystemObject.cs プロジェクト: caisimongit/cms-1
 /// <summary>
 /// 操作对象是否存在
 /// </summary>
 public static bool IsExist(string file, FsoMethod method)
 {
     if (method == FsoMethod.File)
     {
         return File.Exists(file);
     }
     return ((method == FsoMethod.Folder) && Directory.Exists(file));
 }
コード例 #38
0
ファイル: FileSystemObject.cs プロジェクト: caisimongit/cms-1
 /// <summary>
 /// 移动文件
 /// </summary>
 public static void Move(string oldFile, string newFile, FsoMethod method)
 {
     if (method == FsoMethod.File)
     {
         File.Move(oldFile, newFile);
     }
     if (method == FsoMethod.Folder)
     {
         Directory.Move(oldFile, newFile);
     }
 }
コード例 #39
0
 /// <summary>
 /// 获取指定目录下的所有目录及其文件信息
 /// </summary>
 /// <param name="dir">文件夹</param>
 /// <param name="method">获取方式。</param>
 /// <returns>DataTable</returns>
 public static DataTable GetDirectoryAllInfos(string dir, FsoMethod method)
 {
     try
     {
         if (!Directory.Exists(dir))
         {
             Directory.CreateDirectory(dir);
         }
         DirectoryInfo dInfo = new DirectoryInfo(dir);
         return GetDirectoryAllInfo(dInfo, method);
     }
     catch
     {
         throw;
     }
 }
コード例 #40
0
ファイル: Log.cs プロジェクト: vawe666/schtasks
        /// <summary>
        /// 获取指定目录下的所有目录及其文件信息
        /// </summary>
        /// <param name="dir">文件夹</param>
        /// <param name="method">获取方式。</param>
        /// <returns>DataTable</returns>
        public static DataTable getDirectoryAllInfos(string dir, FsoMethod method)
        {
            DataTable Dt;

            try
            {
                DirectoryInfo dInfo = new DirectoryInfo(dir);
                Dt = getDirectoryAllInfo(dInfo, method);
            }
            catch (Exception exc)
            {
                throw new Exception(exc.ToString());
            }

            return Dt;
        }
コード例 #41
0
        /// <summary>
        /// 获取指定目录下的所有目录及其文件信息
        /// </summary>
        /// <param name="d">实例化的目录</param>
        /// <param name="method">获取方式。1、仅获取文件夹结构  2、仅获取文件结构  3、同时获取文件和文件夹信息</param>
        /// <returns></returns>
        private static DataTable GetDirectoryAllInfo(DirectoryInfo d, FsoMethod method)
        {
            DataTable Dt = new DataTable();
            DataRow Dr;

            Dt.Columns.Add("name");			//名称
            Dt.Columns.Add("rname");		//名称
            Dt.Columns.Add("content_type");	//文件MIME类型,如果是文件夹则置空
            Dt.Columns.Add("type");			//类型:1为文件夹,2为文件
            Dt.Columns.Add("path");			//文件路径
            Dt.Columns.Add("creatime");		//创建时间
            Dt.Columns.Add("size");			//文件大小

            // 获取文件夹结构信息
            DirectoryInfo[] dirs = d.GetDirectories();
            foreach (DirectoryInfo dir in dirs)
            {
                if (method == FsoMethod.File)
                {
                    Dt = CopyDT(Dt, GetDirectoryAllInfo(dir, method));
                }
                else
                {
                    Dr = Dt.NewRow();

                    Dr[0] = dir.Name;
                    Dr[1] = dir.FullName;
                    Dr[2] = "";
                    Dr[3] = 1;
                    Dr[4] = dir.FullName.Replace(dir.Name, "");
                    Dr[5] = dir.CreationTime;
                    Dr[6] = "";

                    Dt.Rows.Add(Dr);

                    Dt = CopyDT(Dt, GetDirectoryAllInfo(dir, method));
                }
            }

            // 获取文件结构信息
            if (method != FsoMethod.Folder)
            {
                FileInfo[] files = d.GetFiles();
                foreach (FileInfo file in files)
                {
                    Dr = Dt.NewRow();

                    Dr[0] = file.Name;
                    Dr[1] = file.FullName;
                    Dr[2] = file.Extension.Replace(".", "");
                    Dr[3] = 2;
                    Dr[4] = file.DirectoryName + "\\";
                    Dr[5] = file.CreationTime;
                    Dr[6] = file.Length;

                    Dt.Rows.Add(Dr);
                }
            }

            return Dt;
        }
コード例 #42
0
        /// <summary>
        /// 获取指定目录的目录信息
        /// </summary>
        /// <param name="dir">指定目录</param>
        /// <param name="method">获取方式。1、仅获取文件夹结构  2、仅获取文件结构  3、同时获取文件和文件夹信息</param>
        /// <returns>返回 DataTable</returns>
        public static DataTable GetDirectoryInfos(string dir, FsoMethod method)
        {
            DataTable Dt = new DataTable();
            DataRow Dr;

            Dt.Columns.Add("name");//名称
            Dt.Columns.Add("type");//类型:1为文件夹,2为文件
            Dt.Columns.Add("size");//文件大小,如果是文件夹则置空
            Dt.Columns.Add("content_type");//文件MIME类型,如果是文件夹则置空
            Dt.Columns.Add("createTime");//创建时间
            Dt.Columns.Add("lastWriteTime");//最后修改时间

            // 获取文件夹结构信息
            if (method != FsoMethod.File)
            {
                for (int i = 0; i < GetDirs(dir).Length; i++)
                {
                    Dr = Dt.NewRow();
                    DirectoryInfo d = new DirectoryInfo(GetDirs(dir)[i]);

                    Dr[0] = d.Name;
                    Dr[1] = 1;
                    Dr[2] = "";
                    Dr[3] = "";
                    Dr[4] = d.CreationTime;
                    Dr[5] = d.LastWriteTime;

                    Dt.Rows.Add(Dr);
                }
            }

            // 获取文件结构信息
            if (method != FsoMethod.Folder)
            {
                for (int i = 0; i < GetFiles(dir).Length; i++)
                {
                    Dr = Dt.NewRow();
                    FileInfo f = new FileInfo(GetFiles(dir)[i]);

                    Dr[0] = f.Name;
                    Dr[1] = 2;
                    Dr[2] = f.Length;
                    Dr[3] = f.Extension.Replace(".", "");
                    Dr[4] = f.CreationTime;
                    Dr[5] = f.LastWriteTime;

                    Dt.Rows.Add(Dr);
                }
            }

            return Dt;
        }
コード例 #43
0
 /// <summary>
 /// 删除文件或文件夹
 /// </summary>
 /// <param name="file">文件或文件夹及其路径</param>
 /// <param name="method">删除方式:1、为删除文件,2、为删除文件夹</param>
 public static void Delete(string file, FsoMethod method)
 {
     try
     {
         if (method == FsoMethod.File)
         {
             File.Delete(file);
         }
         if (method == FsoMethod.Folder)
         {
             Directory.Delete(file, true);//删除该目录下的所有文件以及子目录
         }
     }
     catch (Exception exc)
     {
         throw new Exception(exc.ToString());
     }
 }
コード例 #44
0
 /// <summary>
 /// 移动文件或文件夹
 /// </summary>
 /// <param name="oldFile">原始文件或文件夹</param>
 /// <param name="newFile">目标文件或文件夹</param>
 /// <param name="method">移动方式:1、为移动文件,2、为移动文件夹</param>
 public static void Move(string oldFile, string newFile, FsoMethod method)
 {
     try
     {
         if (method == FsoMethod.File)
         {
             File.Move(oldFile, newFile);
         }
         if (method == FsoMethod.Folder)
         {
             Directory.Move(oldFile, newFile);
         }
     }
     catch (Exception exc)
     {
         throw new Exception(exc.ToString());
     }
 }
コード例 #45
0
 /// <summary>
 /// 新建文件或文件夹
 /// </summary>
 /// <param name="file">文件或文件夹及其路径</param>
 /// <param name="method">新建方式</param>
 public static void Create(string file, FsoMethod method)
 {
     try
     {
         if (method == FsoMethod.File)
         {
             WriteFile(file, "");
         }
         else if (method == FsoMethod.Folder)
         {
             Directory.CreateDirectory(file);
         }
     }
     catch (Exception exc)
     {
         throw new Exception(exc.ToString());
     }
 }