private void button4_Click(object sender, EventArgs e)
{
FileStream outputFileStream = new FileStream("log.txt", FileMode.Create, FileAccess.Write);
StreamWriter writer = new StreamWriter(outputFileStream);
// writing block
string originalPathFile = @"C:\Users\user\Downloads\CaptchaCollection\Small\";
string duplicatePath = @"C:\Users\user\Downloads\CaptchaCollection\Small\Duplicates\";
string movedOriginal = @"C:\Users\user\Downloads\CaptchaCollection\Small\Sorted\";
var files = Directory.GetFiles(originalPathFile)
.Select(nameWithExtension => Path.GetFileNameWithoutExtension(nameWithExtension))
.Where(name => { int number; return int.TryParse(name, out number); })
.Select(name => int.Parse(name))
.OrderBy(number => number).ToArray();
while (files.Length > 1)
{
string duplicateOfFolder = Directory.CreateDirectory(duplicatePath + files[0].ToString()).FullName;
for (int j = 1; j < files.Length; j++)
{
Bitmap im1 = new Bitmap(originalPathFile + files[0].ToString() + ".png");
Bitmap im2 = new Bitmap(originalPathFile + files[j].ToString() + ".png");
if (compare(im1, im2))
{
File.Move(originalPathFile + files[j].ToString() + ".png", duplicateOfFolder + files[j].ToString() + ".png");
writer.WriteLine(files[j].ToString() + ".png" + " is a duplicate of " + files[0].ToString() + ".png \n");
}
}
File.Move(originalPathFile + files[0].ToString() + ".png", movedOriginal + files[0].ToString() + ".png");
writer.WriteLine(files[0].ToString() + ".png " + "has had its duplicates removed.");
files = Directory.GetFiles(originalPathFile)
.Select(nameWithExtension => Path.GetFileNameWithoutExtension(nameWithExtension))
.Where(name => { int number; return int.TryParse(name, out number); })
.Select(name => int.Parse(name))
.OrderBy(number => number).ToArray();
}
writer.Close();
outputFileStream.Close();
}
所以这个按钮基本上可以在视觉上移动图像的重复文件。我从我之前问过的一个问题中得到了这个代码。现在我想使用一个新文件夹来放置特定图像的副本。
例如:1.png 有 5 个视觉副本(65.png、87.png、100.png、103.png、156.png)。我想将所有重复项移动到此目录,而不是仅将其放在Duplicates
目录中:C:\Users\user\Downloads\CaptchaCollection\Small\Duplicates\1\
现在发生的事情是它显然正在重命名和重新生成一些图像。我真的无法用语言来描述这件事,因为我真的看不到发生了什么。没有发生的是这些文件没有被移动到重复文件组织的目录中。
将创建文件夹,但不会将其放置在正确的文件夹中。