嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559
本次赞助数额为: 5 元微信扫码支付:5 元
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Xmodel
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
FolderBrowserDialog folder = new FolderBrowserDialog();
folder.Description = "选择所有文件存放目录";
if (folder.ShowDialog() == DialogResult.OK)
{
string sPath = folder.SelectedPath;
//MessageBox.Show(sPath);
txt_y.Text = sPath;
}
}
private void button2_Click(object sender, EventArgs e)
{
FolderBrowserDialog folder = new FolderBrowserDialog();
folder.Description = "选择所有文件存放目录";
if (folder.ShowDialog() == DialogResult.OK)
{
string sPath = folder.SelectedPath;
//MessageBox.Show(sPath);
txt_m.Text = sPath;
}
}
private void button3_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "文本文件|*.txt|所有文件|*.*";
ofd.ValidateNames = true;
ofd.CheckPathExists = true;
ofd.CheckFileExists = true;
if (ofd.ShowDialog() == DialogResult.OK)
{
string strFileName = ofd.FileName;
txt_w.Text = strFileName;
}
}
private void button4_Click(object sender, EventArgs e)
{
if (txt_y.Text!= null && txt_m.Text != null && txt_w.Text != null)
{
string sStuName = string.Empty;
FileStream fs = new FileStream(txt_w.Text, FileMode.Open);
//// "GB2312"用于显示中文字符,写其他的,中文会显示乱码
StreamReader reader = new StreamReader(fs, UnicodeEncoding.GetEncoding("GB2312"));
progressBar1.Visible=true;
label4.Text = "运算中...";
label4.Visible = true;
progressBar1.Value = 0;
progressBar1.Maximum = 100;
progressBar1.Step = 1;//设置没次增长多少
//// 一行一行读取
while ((sStuName = reader.ReadLine()) != null)
{
sStuName = sStuName.Trim().ToString();
if (Directory.Exists(txt_y.Text "\\" sStuName))
{
CopyOldLabFilesToNewLab(txt_y.Text "\\" sStuName, txt_m.Text "\\" sStuName);
}
else
{
if (!System.IO.File.Exists(txt_m.Text "/" "Log" DateTime.Today.ToString("yyyy-MM-dd") ".txt"))
{
FileStream fs1 = new FileStream(txt_m.Text "/" "Log" DateTime.Today.ToString("yyyy-MM-dd") ".txt", FileMode.Create, FileAccess.Write);//创建写入文件
StreamWriter sw = new StreamWriter(fs1);
sw.WriteLine(sStuName "不存在");//开始写入值
sw.Close();
fs1.Close();
}
else
{
FileStream fs2 = new FileStream(txt_m.Text "/" "Log" DateTime.Today.ToString("yyyy-MM-dd") ".txt" "", FileMode.Append, FileAccess.Write);
StreamWriter sr = new StreamWriter(fs2);
sr.WriteLine(sStuName "不存在");//开始写入值
sr.Close();
fs2.Close();
}
}
if (progressBar1.Value < 98)
{ progressBar1.Value = progressBar1.Step; }
}
fs.Close();
progressBar1.Value = 100;
label4.Text = "完成";
MessageBox.Show("完成");
label4.Visible = false;
progressBar1.Visible = false;
}
else
{
MessageBox.Show("请完成选择");
}
}
public bool CopyOldLabFilesToNewLab(string sourcePath, string savePath)
{
if (!Directory.Exists(savePath))
{
Directory.CreateDirectory(savePath);
}
#region //拷贝labs文件夹到savePath下
try
{
string[] labDirs = Directory.GetDirectories(sourcePath);//目录
string[] labFiles = Directory.GetFiles(sourcePath);//文件
if (labFiles.Length > 0)
{
for (int i = 0; i < labFiles.Length; i )
{
if (Path.GetFileName(labFiles[i]) != ".lab")//排除.lab文件
{
File.Copy(sourcePath "\\" Path.GetFileName(labFiles[i]), savePath "\\" Path.GetFileName(labFiles[i]), true);
}
}
}
if (labDirs.Length > 0)
{
for (int j = 0; j < labDirs.Length; j )
{
Directory.GetDirectories(sourcePath "\\" Path.GetFileName(labDirs[j]));
//递归调用
CopyOldLabFilesToNewLab(sourcePath "\\" Path.GetFileName(labDirs[j]), savePath "\\" Path.GetFileName(labDirs[j]));
}
}
}
catch (Exception)
{
return false;
}
#endregion
return true;
}
}
}