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

      

你可能感兴趣的:(case)