DeadByDaylightBackup.Utility/FileUtility.cs
/// <summary>
/// Search for a specific directory
/// Recursive operation
/// </summary>
/// <param name="path">The path that needs to be searched for the folder</param>
/// <param name="directoryname">the foldername to find</param>
/// <returns>Collection of strings</returns>
Search for a specific directory
Recursive operation
Search for a specific directory Recursive operation
public static ICollection<string> SearchForDirectory(string path, string directoryname)
        {
            var info = new DirectoryInfo(path);
            List<string> results = new List<string>(3);
            try
            {
                var directories = info.GetDirectories().Where(x => AccessableDirectory(x.FullName));
                Parallel.ForEach(directories, directory =>
                 {
                     if (directory.Name.Equals(directoryname, StringComparison.OrdinalIgnoreCase))
                     {
                         lock (results)
                         results.Add(directory.FullName);
                     }
                     else
                     {
                         try
                         {
                             var result = SearchForDirectory(directory.FullName, directoryname);
                             if (result.Any())
                                 lock (results) results.AddRange(result);
                         }
                         catch
                         {
                         }
                     }
                 });
            }
            catch { }
            return results;
        }
public static ICollection < string > SearchForDirectory ( string path , string directoryname ) { var info = new DirectoryInfo ( path ) ; List < string > results = new List < string > ( 3 ) ; try { var directories = info . GetDirectories ( ) . Where ( x => AccessableDirectory ( x . FullName ) ) ; Parallel . ForEach ( directories , directory => { if ( directory . Name . Equals ( directoryname , StringComparison . OrdinalIgnoreCase ) ) { lock ( results ) results . Add ( directory . FullName ) ; } else { try { var result = SearchForDirectory ( directory . FullName , directoryname ) ; if ( result . Any ( ) ) lock ( results ) results . AddRange ( result ) ; } catch { } } } ) ; } catch { } return results ; }
Search for a specific directory
Recursive operation
Search for a specific directory Recursive operation
//ERROR
Collection of strings
Collection of strings
path
string
The path that needs to be searched for the folder
The path that needs to be searched for the folder
directoryname
string
the foldername to find
the foldername to find