示例#1
0
        /// <summary>
        /// search in a spesific folder all files contains the search name
        /// </summary>
        /// <param name="filename"> the name of the file to search for</param>
        /// <param name="path">the path to search the files in</param>
        /// <returns>a list of all files in the givven path thar contain the search name</returns>
        public List <SearchResult> SearchForFiles(string filename, string path)
        {
            List <string> Fiels = new List <string>();

            //check if there are files in the folder and add them to the main folder
            string [] filesInFolder = Directory.GetFiles(path);
            if (filesInFolder.Length > 0)
            {
                foreach (string file in filesInFolder)
                {
                    Fiels.Add(file);
                }
            }
            //get all the sub folders on the folder givvan
            string[] FolderList = GetAllFoldersInPath(path);
            if (FolderList.Length > 0)
            {
                //get all fiels in folder
                foreach (string Folder in FolderList)
                {
                    string[] FilesInfoler = GetAllFIlesInPath(Folder);
                    if (FilesInfoler == null)
                    {
                        continue;
                    }
                    else if (FilesInfoler.Length > 0)
                    {
                        foreach (string file in FilesInfoler)
                        {
                            Fiels.Add(file);
                        }
                    }
                }
            }
            if (Fiels.Count == 0)
            {
                NoFielsWereFoundHandler?.Invoke();
                return(null);
            }
            else
            {
                List <SearchResult> FileList = new List <SearchResult>();
                foreach (string file in Fiels)
                {
                    FileList.Add(ConverToSearchResultObjects(file));
                }
                return(FilterList(FileList, filename));
            }
        }
示例#2
0
        /// <summary>
        /// filter a serach result object list acoording to a givven text
        /// </summary>
        /// <param name="FileList"></param>
        /// <param name="filename"></param>
        /// <returns></returns>
        public List <SearchResult> FilterList(List <SearchResult> FileList, string filename)
        {
            List <SearchResult> FilterList = new List <SearchResult>();

            foreach (SearchResult item in FileList)
            {
                if (item.FileName.ToLower().Contains(filename.ToLower()))
                {
                    WhenFileIsFoundHandler?.Invoke(item);
                    FilterList.Add(item);
                }
            }
            if (FilterList.Count == 0)
            {
                NoFielsWereFoundHandler?.Invoke();
            }
            return(FilterList);
        }