zoukankan      html  css  js  c++  java
  • 文件拷贝

    /// <summary>
    /// ディレクトリをコピーする   http://dobon.net/vb/dotnet/file/copyfolder.html
    /// </summary>
    /// <param name="sourceDirName">コピーするディレクトリ</param>
    /// <param name="destDirName">コピー先のディレクトリ</param>

    public static void CopyDirectory(
        string sourceDirName, string destDirName)
    {
        //コピー先のディレクトリがないときは作る
        if (!System.IO.Directory.Exists(destDirName))
        {
            System.IO.Directory.CreateDirectory(destDirName);
            //属性もコピー
            System.IO.File.SetAttributes(destDirName,
                System.IO.File.GetAttributes(sourceDirName));
        }

        //コピー先のディレクトリ名の末尾に"\"をつける
        if (destDirName[destDirName.Length - 1] !=
                System.IO.Path.DirectorySeparatorChar)
            destDirName = destDirName + System.IO.Path.DirectorySeparatorChar;

        //コピー元のディレクトリにあるファイルをコピー
        string[] files = System.IO.Directory.GetFiles(sourceDirName);
        foreach (string file in files)
            System.IO.File.Copy(file,
                destDirName + System.IO.Path.GetFileName(file), true);

        //コピー元のディレクトリにあるディレクトリについて、
        //再帰的に呼び出す

        string[] dirs = System.IO.Directory.GetDirectories(sourceDirName);
        foreach (string dir in dirs)
            CopyDirectory(dir, destDirName + System.IO.Path.GetFileName(dir));
    }
    antony
    :antony1029@163.com
    :http://antony1029.cnblogs.com
  • 相关阅读:
    maven更新远程仓库速度太慢解决方法
    maven安装配置
    myeclipse中配置maven
    java数组的常用函数
    在数组中插入元素
    MySQL的表使用
    MySQL的数据库与表格创建
    节点的添加与删除
    html常用的综合体
    标签的类添加与删除
  • 原文地址:https://www.cnblogs.com/antony1029/p/1287145.html
Copyright © 2011-2022 走看看