TinyMind
.net.cn
首页
资讯
文章
注册
登录
Robocopy use case
higirle
关注文章
TinyMind专栏频道
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)
{
StringBuilderpath
=
new
StringBuilder();
path.Append(sourcePath);
path.Append(
"
"
);
path.Append(destination);
path.Append(
"
\\
"
+
i.ToString());
path.Append(
"
AAA.Zip
"
);
Processprocess
=
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
(Processtemp
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)
{
DirectoryInfodirectoryInfo
=
new
DirectoryInfo(
string
.Format(destination
+
"
\\{0}
"
,index.ToString()));
FileInfo[]fileInfo
=
directoryInfo.GetFiles(
"
AAA.zip
"
);
string
tableName
=
string
.Empty;
foreach
(FileInfofile
in
fileInfo)
{
Guidguid
=
Guid.NewGuid();
if
(
string
.Equals(file.Name,
"
AAA.zip
"
,StringComparison.OrdinalIgnoreCase))
{
string
newPath
=
destination
+
"
\\
"
+
guid.ToString()
+
file.Extension;
File.Move(@file.FullName,@newPath);
}
}
}
}
}
优质内容筛选与推荐
>>
1、阶段1 语言基础+高级_1-3-Java语言高级_06-File类与IO流_05 IO字符流_5_flush方法和close方法的区别
2、js
3、搭建Android环境及Eclipse优化
4、 解决水晶报表不显示工具栏图标的问题
5、微信小程序开发系列教程三:微信小程序的调试方法
赞赏
长按二维码向我转账
受苹果公司新规定影响,微信 iOS 版的赞赏功能被关闭,可通过二维码转账支持公众号。
阅读
好看
已推荐到看一看
你的朋友可以在“发现”-“看一看”看到你认为好看的文章。
取消
推荐
我知道了
已取消,“好看”想法已同步删除
知道了
已推荐到看一看
和朋友分享想法
最多200字,当前共
字
发送
已发送
朋友将在看一看看到
确定
分享你的想法...
取消
分享想法到看一看
确定
最多200字,当前共
字
发送中
网络异常,请稍后重试
知道了
微信扫一扫
关注该公众号
0
│
收藏
│
举报