zoukankan      html  css  js  c++  java
  • C#复制文件代码

    private void Copy()
        {
            DirectoryInfo dir = new DirectoryInfo("c:\\CSS");
            CopyDirectorysAndFiles("c:\\test", dir);
        }
    
        private void CopyDirectorysAndFiles(string dest, DirectoryInfo srcdir)
        {
            if (dest.LastIndexOf('\\') != (dest.Length - 1))
            {
                dest += "\\";
            }
            string destPath = dest +srcdir.Name + "\\";
            if (!Directory.Exists(destPath))
            {
               Directory.CreateDirectory(destPath);
            }
            FileInfo[] files = srcdir.GetFiles();
            foreach (FileInfo file in files)
            {
                file.CopyTo(destPath + file.Name, true);
            }
            DirectoryInfo[] dirs = srcdir.GetDirectories();
            foreach (DirectoryInfo dirInfo in dirs)
            {
                CopyDirectorysAndFiles(destPath, dirInfo);
            }
        } 

    -----------------------------------
    C#拷贝文件原来的文件路径名FileOldPath;
    新的文件路径名:FileNewPath,
    那就可以用

    File.Move(FileOldPath,FileNewPath) 
    或者File.Copy(FileOldPath,FileNewPath) 
    注意的是这里的路径是文件夹路径+文件名,可以用Path.Combine()来实现
    ----------------------------------
    一般是先复制,再删除~
    System.IO.File.Move(File, newfile); 
    System.IO.File.Copy(File, newfile); 
    System.IO.File.Detele(File); 
  • 相关阅读:
    动态表格
    Palindrome Number
    String to Integer (atoi) ???
    Reverse Integer
    Two Sum
    Path Sum
    Minimum Depth of Binary Tree
    Plus One
    Maximum Depth of Binary Tree
    Symmetric Tree
  • 原文地址:https://www.cnblogs.com/cnaspnet/p/1612099.html
Copyright © 2011-2022 走看看