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);
                    }
                }
            }
        
        }
    }

          
    做个快乐的自己。
  • 相关阅读:
    阿里云OSS对象存储 简单上传文件
    [转]eclipse查看某个java类属于哪个jar包
    win7自带照片查看器
    代码规范,李师兄的指导
    Python 结巴分词模块
    Python requests模块
    CTF
    Python requests模块在Windows下安装
    CentOS 6.5部署HTTP WEB服务器和FTP服务器
    Django搭建博客后台
  • 原文地址:https://www.cnblogs.com/Jessy/p/2135372.html
Copyright © 2011-2022 走看看