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
  • 相关阅读:
    共用体
    建立动态链表
    动态分配储存与链表
    结构指针变量作函数参数
    R语言实战 第7章
    R-6 线性回归模型流程
    R-5 相关分析-卡方分析
    R-4 方差分析
    R-3 t分布--t置信区间--t检验
    R-2
  • 原文地址:https://www.cnblogs.com/antony1029/p/1287145.html
Copyright © 2011-2022 走看看