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
  • 相关阅读:
    #ASP.NET Core 1.0 Key Features
    #asp.net core mvc 的视图注入
    # asp.net core 1.0 项目结构
    dotnet core 初试两个小问题解决
    1044 火星数字(20 分)
    1043 输出PATest(20 分)
    1042 字符统计(20 分)
    1041 考试座位号(15 分)
    1040 有几个PAT(25 分)
    1039 到底买不买(20 分)
  • 原文地址:https://www.cnblogs.com/antony1029/p/1287145.html
Copyright © 2011-2022 走看看