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 fileCheck
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender
, EventArgs e
)
{
FolderBrowserDialog dialog
= new FolderBrowserDialog();
dialog
.Description
= "请选择文件路径";
string foldPath
;
if (dialog
.ShowDialog() == DialogResult
.OK
)
{
foldPath
= dialog
.SelectedPath
;
List
<String
> listDoc
= new List<string>();
List
<String
> listExcel
= new List<string>();
DirectoryInfo theFolder
= new DirectoryInfo(foldPath
);
FileInfo
[] thefileInfo
= theFolder
.GetFiles("*.doc", SearchOption
.TopDirectoryOnly
);
FileInfo
[] thefileInfoExcel
= theFolder
.GetFiles("*.xls", SearchOption
.TopDirectoryOnly
);
foreach (FileInfo NextFile in thefileInfo
)
{
string[] temp
= NextFile
.FullName
.Replace(".doc", "").Split(new string[] {foldPath
+"\\"}, StringSplitOptions
.RemoveEmptyEntries
);
listDoc
.Add(temp
[0]);
}
foreach (FileInfo NextFileExcel in thefileInfoExcel
)
{
string[] temp
= NextFileExcel
.FullName
.Replace(".xls", "").Split(new string[] {foldPath
+"\\"}, StringSplitOptions
.RemoveEmptyEntries
);
listExcel
.Add(temp
[0]);
}
char[] separator
= {'_'};
foreach (string item
in listExcel
)
{
string[] name
= item
.Split(separator
);
if (!listDoc
.Contains(name
[0]))
{
if (!Directory
.Exists(foldPath
+"\\bak"))
{
Directory
.CreateDirectory(foldPath
+ "\\bak");
}
if (System
.IO
.File
.Exists(foldPath
+ "\\" + item
+ ".xls"))
{
File
.Move(foldPath
+ "\\" + item
+ ".xls", foldPath
+ "\\bak" + "\\" + item
+ ".xls");
}
}
}
MessageBox
.Show("处理完成!");
}
}
}
}
转载请注明原文地址: https://lol.8miu.com/read-15018.html