Click here to Skip to main content
14,267,453 members

.NET Framework

 
PinnedHOW TO ANSWER A QUESTION Pin
Chris Maunder16-Jul-09 3:09
adminChris Maunder16-Jul-09 3:09 
PinnedHow to get an answer to your question Pin
Chris Maunder16-Jul-09 3:05
adminChris Maunder16-Jul-09 3:05 
QuestionOptimize Directory Parsing and TreeView Population Pin
Harley Burton13-Aug-19 3:16
memberHarley Burton13-Aug-19 3:16 
AnswerRe: Optimize Directory Parsing and TreeView Population Pin
Richard Deeming13-Aug-19 3:51
mveRichard Deeming13-Aug-19 3:51 
GetFiles and GetDirectories return an array containing all files/directories found. The methods can't return until that array has been populated. You should probably try using EnumerateFiles and EnumerateDirectories instead, and try to remove the ToArray calls.

DirectoryInfo.EnumerateFiles Method (System.IO) | Microsoft Docs[^]
DirectoryInfo.EnumerateDirectories Method (System.IO) | Microsoft Docs[^]

You're also going to want to skip "reparse-point" directories, which can have your code running around in circles.
Reparse Points - Windows applications | Microsoft Docs[^]

There's no need to pass *.* as the search pattern; just omit the parameter.

I'd be inclined to avoid the simple LINQ filters, since you're processing a lot of directories.

Try something like this:
public void ParseProfile(TreeNode parent_node, DirectoryInfo parent_di = null)
{
    if (parent_di == null) parent_di = new DirectoryInfo(parent_node.Name);
    
    try
    {
        foreach (DirectoryInfo dir in parent_di.EnumerateDirectories())
        {
            if ((dir.Attributes & FileAttributes.Hidden) != 0) continue;
            if ((dir.Attributes & FileAttributes.ReparsePoint) != 0) continue;
            TreeNode this_node = parent_node.Nodes.Add(dir.FullName, dir.Name, 0);
            ParseProfile(this_node, dir);
        }
        
        foreach (FileInfo file in parent_di.EnumerateFiles())
        {
            if ((file.Attributes & FileAttributes.Hidden) != 0) continue;
            parent_node.Nodes.Add(file.FullName, file.Name, 1);
        }
    }
    catch (UnauthorizedAccessException e)
    {
        inaccessible.Add(parent_di.FullName);
        Log(e.Message, LOG_LEVEL.access);
    }
    catch (DirectoryNotFoundException e)
    {
        momentaries.Add(parent_di.FullName);
        Log(e.Message, LOG_LEVEL.warning);
    }
    catch (Exception e)
    {
        Log(e.Message, LOG_LEVEL.debug);
        throw;
    }
}




"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer


modified 5 days ago.

GeneralRe: Optimize Directory Parsing and TreeView Population Pin
Harley Burton13-Aug-19 10:41
memberHarley Burton13-Aug-19 10:41 
GeneralRe: Optimize Directory Parsing and TreeView Population Pin
Richard Deeming13-Aug-19 22:35
mveRichard Deeming13-Aug-19 22:35 
GeneralRe: Optimize Directory Parsing and TreeView Population Pin
Harley Burton14-Aug-19 4:52
memberHarley Burton14-Aug-19 4:52 
QuestionWindows Service Installer Problem Pin
Kevin Marois7-Aug-19 6:14
professionalKevin Marois7-Aug-19 6:14 
AnswerRe: Windows Service Installer Problem Pin
Richard Andrew x647-Aug-19 11:47
professionalRichard Andrew x647-Aug-19 11:47 
GeneralRe: Windows Service Installer Problem Pin
Kevin Marois7-Aug-19 12:13
professionalKevin Marois7-Aug-19 12:13 
Question.Net Core web tiff vieawer Pin
Member 145516927-Aug-19 3:55
memberMember 145516927-Aug-19 3:55 
AnswerRe: .Net Core web tiff vieawer Pin
Richard MacCutchan7-Aug-19 4:14
protectorRichard MacCutchan7-Aug-19 4:14 
GeneralRe: .Net Core web tiff vieawer Pin
Member 145516927-Aug-19 4:31
memberMember 145516927-Aug-19 4:31 
GeneralRe: .Net Core web tiff vieawer Pin
Richard MacCutchan7-Aug-19 5:55
protectorRichard MacCutchan7-Aug-19 5:55 
AnswerRe: .Net Core web tiff vieawer Pin
Richard Deeming7-Aug-19 9:44
mveRichard Deeming7-Aug-19 9:44 
QuestionInstalling A Windows Service on Win 10 With Windows Defender Pin
Kevin Marois6-Aug-19 7:23
professionalKevin Marois6-Aug-19 7:23 
AnswerRe: Installing A Windows Service on Win 10 With Windows Defender Pin
Richard Andrew x646-Aug-19 12:13
professionalRichard Andrew x646-Aug-19 12:13 
SuggestionRe: Installing A Windows Service on Win 10 With Windows Defender Pin
Richard Deeming7-Aug-19 9:40
mveRichard Deeming7-Aug-19 9:40 
QuestionHow to crystal report Short by Month.Year Pin
NSE India5-Aug-19 22:08
memberNSE India5-Aug-19 22:08 
AnswerRe: How to crystal report Short by Month.Year Pin
Richard Andrew x646-Aug-19 12:23
professionalRichard Andrew x646-Aug-19 12:23 
AnswerRe: How to crystal report Short by Month.Year Pin
Richard Deeming7-Aug-19 9:38
mveRichard Deeming7-Aug-19 9:38 
QuestionFind Assembly Dependancies Pin
Kevin Marois1-Aug-19 7:17
professionalKevin Marois1-Aug-19 7:17 
AnswerRe: Find Assembly Dependencies Pin
Richard Deeming1-Aug-19 9:05
mveRichard Deeming1-Aug-19 9:05 
QuestionUsing a GAC-registered assembly in a web application Pin
tiwal23-Jul-19 0:39
membertiwal23-Jul-19 0:39 
AnswerRe: Using a GAC-registered assembly in a web application Pin
Eddy Vluggen23-Jul-19 1:13
mveEddy Vluggen23-Jul-19 1:13 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.