locked
Traverse Folder Tree Parallel , get all file paths in subfolder and apply an action to them RRS feed

  • General discussion

  • usefull:

    private static void TraverseFolderTreeParallel(string path, Action<string> action)
            {
                try
                {
                    path = path.ToUpperInvariant();
                    path = Path.GetFullPath(path);//normalize path
    
                     var files = Directory.GetFiles(path, "*.*", SearchOption.AllDirectories).AsParallel();
                    foreach (var file in files)
                    {
                        action(file.ToUpperInvariant());
                     }
                }
                catch (AggregateException ae)
                {
                    ae.Handle(ex => true);
                }
            }

    Monday, March 11, 2013 3:49 PM

All replies