我写了一个程序,代码似乎工作,但它不工作。它给出了 IO 异常是未处理的错误。有些人说我,你应该删除一些东西,因为程序试图同时使用同一个文件。请帮我!!
namespace App1508
{
public partial class Form2 : Form
{
string goodDir = "C:\\GOOD\\";
string badDir = "C:\\BAD\\";
string fromDir = "C:\\DENEME\\";
List<Image> images = null;
int index = -1;
FileInfo[] finfos = null;
public Form2()
{
InitializeComponent();
DirectoryInfo di = new DirectoryInfo(@"C:\DENEME");
finfos = di.GetFiles("*.jpg",SearchOption.TopDirectoryOnly);
images = new List<Image>();
foreach (FileInfo fi in finfos)
{
images.Add(Image.FromFile(fi.FullName));
}
}
private void button1_Click(object sender, EventArgs e)
{
finfos[index].MoveTo(Path.Combine("C:\\GOOD", finfos[index].Name));
}
private void pictureBox1_Click(object sender, EventArgs e)
{
index++;
if (index < 0 || index >= images.Count)
index = 0;
pictureBox1.Image = images[index];
}
private void button2_Click(object sender, EventArgs e)
{
finfos[index].MoveTo(Path.Combine("C:\\BAD", finfos[index].Name));
}
}
}