C# 文件copy和文件删除

来源:互联网 发布:淘宝如何设置最低折扣 编辑:程序博客网 时间:2024/05/16 11:23

C# 文件copy和文件删除

       public bool CopyFile(string SourcePath, string CopyPathFoder)        {            bool bfg = false;            if (!Directory.Exists(CopyPathFoder))            {                Directory.CreateDirectory(CopyPathFoder);            }            string[] childfile = SourcePath.Split('\\');            File.Copy(SourcePath, CopyPathFoder + @"\" + childfile[childfile.Length - 1], true);            bfg = true;            return bfg;        }        /// <summary>        /// 删除文件        /// </summary>        /// <param name="Path"></param>        /// <returns></returns>        public bool FileDel(string Path)        {            try            {                if (File.Exists(Path))                {                    FileInfo fi = new FileInfo(Path);                    if (fi.Attributes.ToString().IndexOf("ReadOnly") != -1)                    {                        fi.Attributes = FileAttributes.Normal;                    }                    File.Delete(Path);                    return true;                }            }            catch (Exception)            {                return false;            }            return false;        }


 

1 0
原创粉丝点击