P
peter.rietmann
Hi
I have an application that records the paths of images in a database
table, while the images are stored on a File System. Unfortunatly there
has been an import job running and has copied over one million images
into one of the directories by mistake. In the database I have
approximately 300,000 images.
I have created a job to recursively scan my image directories , check
the file names in the database, if the image is not in the database
then I delete the image from the hard drive. This works ok but one
directory has more than one millon records (16 GB)inside it and the
application crashes when trying to access the files in that directory.
Here an example of the code that I use
private void ScanImageDirectory(string sourceDir)
{
DirectoryInfo di = new DirectoryInfo(sourceDir);
FileInfo [] fi = di.GetFiles();
foreach(FileInfo file in fi)
{
if(!FileExistsInDatabase(file.Name))
{
file.Delete();
}
}
string [] subdirEntries = Directory.GetDirectories
(sourceDir);
foreach(string subdir in subdirEntries)
{
ScanImageDirectory(subdir);
}
}
Has anyone an idea how to work with large directories to complete my
task ?
thanks in advance
I have an application that records the paths of images in a database
table, while the images are stored on a File System. Unfortunatly there
has been an import job running and has copied over one million images
into one of the directories by mistake. In the database I have
approximately 300,000 images.
I have created a job to recursively scan my image directories , check
the file names in the database, if the image is not in the database
then I delete the image from the hard drive. This works ok but one
directory has more than one millon records (16 GB)inside it and the
application crashes when trying to access the files in that directory.
Here an example of the code that I use
private void ScanImageDirectory(string sourceDir)
{
DirectoryInfo di = new DirectoryInfo(sourceDir);
FileInfo [] fi = di.GetFiles();
foreach(FileInfo file in fi)
{
if(!FileExistsInDatabase(file.Name))
{
file.Delete();
}
}
string [] subdirEntries = Directory.GetDirectories
(sourceDir);
foreach(string subdir in subdirEntries)
{
ScanImageDirectory(subdir);
}
}
Has anyone an idea how to work with large directories to complete my
task ?
thanks in advance