///<summary>
        /// Finds a file in a directory and searches subdirectories
        ///</summary>
        ///<param name="fileName">The filename to find</param>
        ///<param name="directory">The starting directory to search</param>
        ///<returns></returns>
        public string Find(string fileName, string directory)
        {
            IEnumerable <string> filesInDirectory = _fileSystem.GetFilesIn(directory);

            if (filesInDirectory != null)
            {
                foreach (string file in filesInDirectory)
                {
                    if (Path.GetFileName(file) == fileName)
                    {
                        return(file);
                    }
                }
            }


            IEnumerable <string> subDirectories = _fileSystem.GetDirectories(directory);

            if (subDirectories != null)
            {
                foreach (string subDirectory in subDirectories)
                {
                    var find = Find(fileName, subDirectory);
                    if (find != null)
                    {
                        return(find);
                    }
                }
            }
            return(null);
        }
Example #2
0
        private IList <String> GetAllFilesMatching(string directory, string filter, bool recursive)
        {
            string[]      files    = System.IO.Directory.GetFiles(directory, filter);
            List <string> matching = files.ToList();

            if (recursive)
            {
                foreach (string subDirectory in _fileSystemWrapper.GetDirectories(directory))
                {
                    matching.AddRange(GetAllFilesMatching(subDirectory, filter, true));
                }
            }
            return(matching);
        }