0

It's not similar to anything posted on the internet, I am the author of this project that was created some 8 years ago. This project is for my thesis today for my Masteral Degree. I need to improve the GetFiles() to filter the allowed file types since this project is intended for my school. This software acts like TinEye or Turnitin by checking the similarity of the picture to be checked for plagiarism.

This is the error I am getting now. "Out of memory" please see the image in the link

Error Message

I've figured it out already the cause of the problem, but I can't find a way to resolve it.

I'll post my project file here, you can check it to see the line of code.

In the File Form1.cs at line number 88 it states the code

_fileArray= System.IO.Directory.GetFiles(fbd.SelectedPath, "\*.\*",
                                  System.IO.SearchOption.AllDirectories);

I can't find a way to filter the file types to be initially stored already to variable string[] _fileArray

I can't redo the entire project since my time is short for the deadline I will appreciate any help to fix the error.

Mohammad Akbari
  • 4,486
  • 6
  • 43
  • 74

2 Answers2

1

You should use the Directory.EnumerateFiles() which returns an IEnumerable<string> which is lazy.

Don't store them into an array or list. Just iterate it directly.

If you need to present them in a listbox/listview and iterating takes a lot of time, store the filenames into a textfile, which can be loaded more easily and faster.

var files = Directory.EnumerateFiles(fbd.SelectedPath, "*.*", SearchOption.AllDirectories);

foreach(var file in files)
{
    // do your thing...
}
Jeroen van Langen
  • 21,446
  • 3
  • 42
  • 57
0

IF I understand correctly, you are looking to filter the files for certain extensions (.jpg, .gif, etc..).

If so, try this answer: Directory.GetFiles(dir, "*.jpg", SearchOption.AllDirectories)

found here: https://stackoverflow.com/a/13301082/10880378

Bebandit
  • 26
  • 5