【发布时间】:2016-01-18 11:24:03
【问题描述】:
我有一个要将文件复制到的计算机列表。
我正在尝试创建一个标签,显示当时正在复制到哪台计算机。例如:“Copying to computer1... (x of 10)”,其中 10 基于字符串数组中的行数:
var lineCount = File.ReadLines(complist).Count();
如何在每次复制新文件时更改第一个数字 (x)? (10 个中的 1 个)、(10 个中的 2 个)等...
这是我的标签的样子:
label2.Text = ("Copying to " + @computer + "... ( of " + lineCount + ")");
编辑:这是我的复制操作。这些文件被复制到每个远程系统。
string complist = openFileDialog2.FileName;
string patch = textBox2.Text;
string fileName = patch;
string patchfile = Path.GetFileName(fileName);
var lineCount = File.ReadLines(complist).Count();
foreach (string line in File.ReadLines(complist))
{
//Checks if C:\PatchUpdates exists on remote machine. If not, a folder is created.
if (!Directory.Exists(@"\\" + line + @"\C$\PatchUpdates"))
{
Directory.CreateDirectory(@"\\" + line + @"\C$\PatchUpdates");
}
//XCOPY patch to every computer
System.Diagnostics.Process processCopy = new System.Diagnostics.Process();
ProcessStartInfo StartInfo = new ProcessStartInfo();
StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
StartInfo.FileName = "cmd";
StartInfo.Arguments = string.Format("/c xcopy " + patch + " " + @"\\{0}\C$\PatchUpdates /K /Y", line);
processCopy.StartInfo = StartInfo;
processCopy.Start();
label2.Text = ("Copying to " + @line + "... (" + @num + " of " + @lineCount + ")");
processCopy.WaitForExit();
【问题讨论】:
-
你能显示循环文件并进行复制的代码吗?
-
设置一个计数器,在循环开始内增加
-
已编辑以显示文件的复制。
标签: c#