Callbacks in VB.NET for DirectoryInfo.GetFiles

  • Thread starter Thread starter Tom Scales
  • Start date Start date
T

Tom Scales

OK, I admit, I am not a VB.NET expert and am still learning, but have run
into an annoying problem. I'm writing a program that has to search the file
system and therefore processes large numbers of directories and files. I've
figured out DirectoryInfo (it's pretty simple), but when I invoke
DirectoryInfo.GetFiles (or even DirectoryInfo.GetDirectories), it can take
forever. Some of the directories have thousands of files in them.

So, my application just sits there and the user thinks it's locked up.

I'm looking for a way to get a callback from the GetFiles function so that I
can actually provide a reasonable processbar. I know I could just flash up a
progress bar or something, but I want the information to be meaningful.

Can someone point me in the right direction. Sample code, ideas, any
suggestions would be welcome.

Thanks in advance for the help. I've searched and searched prior to asking
but can't seem to find what I am looking for.

Tom
 
* "Tom Scales said:
OK, I admit, I am not a VB.NET expert and am still learning, but have run
into an annoying problem. I'm writing a program that has to search the file
system and therefore processes large numbers of directories and files. I've
figured out DirectoryInfo (it's pretty simple), but when I invoke
DirectoryInfo.GetFiles (or even DirectoryInfo.GetDirectories), it can take
forever. Some of the directories have thousands of files in them.

So, my application just sits there and the user thinks it's locked up.

I'm looking for a way to get a callback from the GetFiles function so that I
can actually provide a reasonable processbar. I know I could just flash up a
progress bar or something, but I want the information to be meaningful.

You will find a nice sample here (notice that the sample is written in
C# and must be translated to VB.NET before it can be used in VB.NET):

<http://www.palmbytes.de/content/dotnetlibs/filesearchlib.htm>
 
What you want to do is create a class that itself creates a thread to do the
work for you. This thread then executes a "delegate" function on your main
class which can update the progress bar.
 
I know how to do that, but I'm stuck on the SINGLE statement. VB.NET
doesn't return control or information to me. It's not like I'm in a loop I
can control.
 
Oh I see your point. Well, if you are executing a method that will take a
long time, without giving feedback, the only way to go is to "fake" the
progress bar - or better, just display an animation (like an egg timer going
around and around).
 
I can do that, but it sure is ugly. Surely the GetFiles method is firing
SOME event into my application that I can catch and use.

Tom
 
Yup, was just about to say use FindFirst etc. This is the way to go if you
want accurate progress feedback.
 
Why not have a rather large label on your form that displays the path & file
names as your program runs thru the directories? That way your user would
see that something is happening.
james
 
Because it sometimes takes 10 minutes per directory -- they think it is
locked up.
When you say it's taking ten minutes, do you mean for the just the files in
the root of that directory or a recursive search of the files in any
subdirectories? If the former...wow, you must have a lot of files...and
sorry, I can't help. But if you mean the latter, you could at least give
the user feedback when a new subdirectory was being searched.

I have developed an application which searches a set of folders recursively
for mp3 files. As each new individual folder is searched, be it one of the
main search folders or one of the subfolders therein, the folder name is
displayed. I've never run across a directory which contained so many files
in the root that the user would mistake the application for being locked up.
Perhaps you could implement something like this.

HTH

- Mitchell S. Honnert
 
10 minutes per directory.

1,500,000 files.

Tom
Mitchell S. Honnert said:
When you say it's taking ten minutes, do you mean for the just the files in
the root of that directory or a recursive search of the files in any
subdirectories? If the former...wow, you must have a lot of files...and
sorry, I can't help. But if you mean the latter, you could at least give
the user feedback when a new subdirectory was being searched.

I have developed an application which searches a set of folders recursively
for mp3 files. As each new individual folder is searched, be it one of the
main search folders or one of the subfolders therein, the folder name is
displayed. I've never run across a directory which contained so many files
in the root that the user would mistake the application for being locked up.
Perhaps you could implement something like this.

HTH

- Mitchell S. Honnert




in
 
10 minutes per directory.
1,500,000 files.
This still doesn't answer my question. I think it's most likely that you
mean that the files are in the root of the directory(and not in subfolders
of that directory), but my question was meant to confirm this. Oh well.

- Mitchell S. Honnert
 
Sorry, I was not clear. There are a limited number of directories, each with
40000+ files. Therefore, the status change of a new directories is not
frequent enough to make the user comfortable that appropriate activity is
occuring.

I guess I need to use FindNext, which is not hard to code, but I think it is
pretty silly that the GetFiles does not anticipate this and have a nice
callback.

Tom
 
Back
Top