i'm tryng to separate documents based on qr code,all the pages whitout a QR code end up in the same folder as the first QR it finds, then it creates a new folder and does the same thing whit the next QR it finds, i'm using zxing but when it tries to move the file with the QR it says it's used by another process, here is the code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ZXing;
using System.Drawing;
using ZXing.QrCode;
using System.Threading;
using System.IO;
namespace zxing_qr
{
internal class Program
{
static void Main(string[] args)
{
string srcDir = @"C:\Users\tirocinio2\Documents\moduli d'intervento";
string[] filenames = System.IO.Directory.GetFiles(srcDir);
List<string> buffer = new List<string>(2);
for (int i = 0;i< filenames.Length;i++)
{
string res = decode(filenames, i);
Thread.Sleep(50);
if (res != null)
{
buffer.Add(filenames[i]);
string dest = creaCartella();
for (int j = 0; j < buffer.Count; j++)
{
FileInfo file = new FileInfo(buffer[j]);
file.MoveTo($@"{dest}" + buffer[j].Substring(buffer[j].LastIndexOf('\\')));
}
buffer.Clear();
}
else
{
buffer.Add(filenames[i]);
}
}
Console.WriteLine("premi un tasto per continuare");
Console.ReadKey();
}
static string creaCartella()
{
string destDir = DateTime.Now.ToString().Replace(" ","").Replace("/","_").Replace(":","-");
destDir = @"C:\Users\tirocinio2\Documents\output moduli\" + destDir;
System.IO.Directory.CreateDirectory(destDir);
return destDir;
}
static string decode(string[] filenames,int i)
{
BarcodeReader barcodeReader = new BarcodeReader();
Bitmap barcodeBitmap = (Bitmap)Bitmap.FromFile(filenames[i]);
Result barcodeResult = barcodeReader.Decode(barcodeBitmap);
return barcodeResult.ToString();
}
}
}