zoukankan      html  css  js  c++  java
  • Robocopy use case

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.IO;
    using System.Diagnostics;
    using System.Collections;

    namespace ConsoleApplication2
    {
        
    class Program
        {

            
    static void Main(string[] args)
            {
                List
    <string> paths = new List<string>();
                paths.Add(
    @"\\pat111");
                paths.Add(
    @"\\path12");
                CopyMultiplyFile(paths, 
    @"E:\Copy");

                
    for (int i = 0; i < 2; i++)
                {
                    MoveAndReNameFile(
    @"E:\Copy", i);
                }
            }  
       
            
    private static void CopyFilesToLocal(List<string> paths, string destination)
            {
                List
    <Process> processes = new List<Process>();

                
    int i = 0;

                
    foreach (string sourcePath in paths)
                {
                    StringBuilder path 
    = new StringBuilder();
                    path.Append(sourcePath);
                    path.Append(
    " ");
                    path.Append(destination);            
                    path.Append(
    "\\" + i.ToString());

                    path.Append(
    "   AAA.Zip");

                    Process process 
    = new Process();
                    processes.Add(process);
                    process.StartInfo.FileName 
    = "robocopy";
                    process.StartInfo.Arguments 
    = @path.ToString();
                    process.StartInfo.UseShellExecute 
    = false;
                    process.StartInfo.CreateNoWindow 
    = true;
                    process.Start();
                    i
    ++;
                }

                
    foreach (Process temp in processes)
                {
                    temp.WaitForExit();
                }
            }      

            
    public static void CopyMultiplyFile(List<string> paths, string destination)
            {
                CopyFilesToLocal(paths, destination);

                
    for (int index = 0; index < paths.Count; index++)
                {
                    MoveAndReNameFile(destination, index);
                }
            }
           
    private static void MoveAndReNameFile(string destination, int index)
           {
                DirectoryInfo directoryInfo 
    = new DirectoryInfo(string.Format(destination + "\\{0}", index.ToString()));
                FileInfo[] fileInfo 
    = directoryInfo.GetFiles("AAA.zip");
                
    string tableName = string.Empty;

                
    foreach (FileInfo file in fileInfo)
                {
                    Guid guid 
    = Guid.NewGuid();

                    
    if (string.Equals(file.Name, "AAA.zip", StringComparison.OrdinalIgnoreCase))
                    {
                        
    string newPath = destination + "\\" + guid.ToString() + file.Extension;
                        File.Move(@file.FullName, @newPath);
                    }
                }
            }
        
        }
    }

          
    做个快乐的自己。
  • 相关阅读:
    12 个最佳 GNOME(GTK)主题
    Ubuntu18.04解决鼠标移动到Gnome顶栏左上角窗口不能平铺( Activites Overview 界面),和应用程序扩展不好用问题。
    常用的GNOME Shell 扩展
    11 个使用 GNOME 3 桌面环境的理由
    值得尝试的十款 GNOME Shell 扩展
    Python快速教程 尾声(转)
    宽恕
    EF code First数据迁移学习笔记(转)
    异步编程 In .NET(转)
    bootstrap + requireJS+ director+ knockout + web API = 一个时髦的单页程序
  • 原文地址:https://www.cnblogs.com/Jessy/p/2135372.html
Copyright © 2011-2022 走看看