I’ve seen this code (and similar) all over the web, but I just cannot get it to work. Whenever I debug it line by line, it breaks out of debugging and loads the application. No error messages are presented, and any code after the “faulty” line remains unprocessed.
Here is the offending code:
foreach (string folder in allFolders)
{
string[] subFolders = Directory.GetDirectories(folder,
"*", SearchOption.AllDirectories);
MessageBox.Show("Test");
}
The foreach loop is entered into, but the message box is never displayed.
If I remove the SearchOption.AllDirectories the code is processed successfully, but I need some way to include all subdirectories within the directories.
Any ideas?
Your code works fine for me.
It seems to me that this method call just takes a lot of time to execute. For example, if there is a root directory in allFolders you have to wait several minutes (depends on your system parameters). Have you checked this code snippet on directories with just a few number of nested directories?
I assumed, that you work in winforms and execution just doesn’t reach MessageBox.Show call.