DeadByDaylightBackup.Utility/FileUtility.cs
/// <summary>
/// Search all drives for the specified folder name, and the searchtarget in it.
/// </summary>
/// <param name="foldername">Name of the folder, no wildcards</param>
/// <param name="searchTarget">desired file, wildcards allowed</param>
/// <returns>array of filepaths</returns>
Search all drives for the specified folder name, and the searchtarget in it.
Search all drives for the specified folder name and the searchtarget in it .
public static string[] FullFileSearch(string foldername, string searchTarget)
        {
            var drives = GetDrives();
            List<string> files = new List<string>(3);
            Parallel.ForEach(drives, new ParallelOptions
            {
                MaxDegreeOfParallelism = 2
            }, drive =>
                {
                    var topLevelDirectories = Directory.GetDirectories(drive).Where(x => AccessableDirectory(x)).ToArray();
                    Parallel.ForEach(topLevelDirectories, new ParallelOptions
                    {
                        MaxDegreeOfParallelism = 2
                    }, dir =>
                    {
                        try
                        {
                            var directories = SearchForDirectory(dir, foldername);
                            Parallel.ForEach(directories, directory =>
                             {
                                 var result = Directory.GetFiles(directory, searchTarget.Trim(), SearchOption.AllDirectories);
                                 if (result.Any())
                                 {
                                     lock (files)
                                     { files.AddRange(result); }
                                 }
                             });
                        }
                        catch
                        {
                        }
                    });
                });
            return files.ToArray();
        }
public static string [ ] FullFileSearch ( string foldername , string searchTarget ) { var drives = GetDrives ( ) ; List < string > files = new List < string > ( 3 ) ; Parallel . ForEach ( drives , new ParallelOptions { MaxDegreeOfParallelism = 2 } , drive => { var topLevelDirectories = Directory . GetDirectories ( drive ) . Where ( x => AccessableDirectory ( x ) ) . ToArray ( ) ; Parallel . ForEach ( topLevelDirectories , new ParallelOptions { MaxDegreeOfParallelism = 2 } , dir => { try { var directories = SearchForDirectory ( dir , foldername ) ; Parallel . ForEach ( directories , directory => { var result = Directory . GetFiles ( directory , searchTarget . Trim ( ) , SearchOption . AllDirectories ) ; if ( result . Any ( ) ) { lock ( files ) { files . AddRange ( result ) ; } } } ) ; } catch { } } ) ; } ) ; return files . ToArray ( ) ; }
Search all drives for the specified folder name, and the searchtarget in it.
Search all drives for the specified folder name and the searchtarget in it .
array of filepaths
array of filepaths
foldername
string
Name of the folder, no wildcards
Name of the folder no wildcards
searchTarget
string
desired file, wildcards allowed
desired file wildcards allowed