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;
        }

C# 文件copy和文件删除的更多相关文章

  1. 文件Copy和文件夹Copy

    文件Copy和文件夹Copy using System.Collections.Generic; using System.Linq; using System.Text; using System. ...

  2. Java 实现文件上传、下载、打包、文件copy、文件夹copy。

    文件and文件夹copy package org.test; import java.io.*; public class FileCopy { /** * 复制单个文件 * * @param old ...

  3. Linux基础知识第三讲,拷贝文件跟移动文件命令

    目录 Linux基础知识第三讲,拷贝文件跟移动文件命令 一丶常用命令 1.tree命令常用选项 2.cp复制文件命令 3.mv 命令的使用 Linux基础知识第三讲,拷贝文件跟移动文件命令 一丶常用命 ...

  4. PHP文件操作,多行句子的读取,file()函数,file_get_contents()函数,file_put_contents()函数,is_file,统计网站pv (访问量),文件的复制 copy,文件重命名 rename,删除文件 unlink

    php中添加utf-8: header("Content-type:text/html;charset='UTF-8'"); 文件操作步骤: 1.在同一目录下建立一个file.tx ...

  5. C#基础-文件夹复制与删除

    代码来源:http://blog.163.com/u_tommy_520/blog/static/20406104420147493933662/ 最近做MVC网站时刚好用到,用以提供一个完整的文件夹 ...

  6. Windows、Linux下文件操作(写、删除)错误的产生原因、及解决方法

    catalog . 引言 . Linux平台上涉及的File IO操作 . Windows平台上涉及的File IO操作 0. 引言 本文试图讨论在windows.linux操作系统上基于C库进行文件 ...

  7. Struts2 文件上传,下载,删除

    本文介绍了: 1.基于表单的文件上传 2.Struts 2 的文件下载 3.Struts2.文件上传 4.使用FileInputStream FileOutputStream文件流来上传 5.使用Fi ...

  8. Linux文件的复制、删除和移动命令

    cp命令  功能:将给出的文件或目录拷贝到另一文件或目录中,就如同DOS下的copy命令一样,功能非常强大.  语法:cp [选项] 源文件或目录 目标文件或目录  说明:该命令把指定的源文件复制到目 ...

  9. Grunt: 拼接代码,js丑化(压缩),css压缩,html压缩,观察文件,拷贝文件,删除文件,压缩文件

    准备工作 grunt 基于nodeJs所以 nodeJs需要的基础配置都需要安装 1.Grunt 安装 npm install -g grunt-cli 这是全局安装 2.在当前文件下npm init ...

随机推荐

  1. HDU [P1704] Rank

    传递闭包裸题 但是本题的Floyd一定要优化,不然会T cpp #include <iostream> #include <cstdio> #include <cstri ...

  2. 洛谷 [P1182] 数列分段

    这是一道典型的二分答案问题(最大值最小,最小值最大)关键是对于细节的处理. 二分的框架: //l=max{num[i]},r=sum{num[i]} while(l<=r){ int m=(l+ ...

  3. 为Docker配置阿里加速器,系统为Debian8

    先停止docker服务 service docker stop 设置阿里加速器 dockerd --registry-mirror=https://063eurcd.mirror.aliyuncs.c ...

  4. mongoDB高级查询$type4array使用解析

    今天在使用mongoDB高级查询$type:符号 -- 4代指Array类型发现一个问题. $type符号: $type操作符是基于BSON类型来检索集合中匹配的数据类型,并返回结果. 下面是mong ...

  5. CentOS下安装XAMPP详细教程(转)

    [原文]http://blog.csdn.net/hel12he/article/details/49781813 现在PHP的集成运行环境越来越多,个人比较喜欢XAMPP,更新速度快,好用,安装便捷 ...

  6. iOS UIFont 字体名字大全

    Font Family: American TypewriterFont: AmericanTypewriterFont: AmericanTypewriter-Bold Font Family: A ...

  7. C/C++语言简介之编程开发

    一.编译器 GCC:GNU组织开发的开源免费的编译器. MinGW:Windows操作系统下的GCC. Clang:开源的BSD协议的基于LLVM的编译器. Visual C++:Microsoft ...

  8. 市面上有没有靠谱的PM2.5检测仪?如何自己动手制作PM2.5检测仪

     市面上能买到的11中常见的pm2.5检测仪 网上大佬实测并不是很准,我这里没测过(全买下来有点贵,贫穷限制了我的想象力) 这些检测仪多数是复合式.多功能的空气质量检测仪.具体就不一一介绍了.这篇文章 ...

  9. node.js简单搭建服务,访问本地站点文件

    1.安装nodejs服务(从官网下载安装),node相当于apache服务器 2.在自己定义的目录下新建服务器文件如 server.js 例如,我在D:\nodeJs下创建了server.js文件 v ...

  10. Spring MVC中Session的正确用法之我见

    Spring MVC是个非常优秀的框架,其优秀之处继承自Spring本身依赖注入(Dependency Injection)的强大的模块化和可配置性,其设计处处透露着易用性.可复用性与易集成性.优良的 ...