FileStore.FileStore.FindFile C# (CSharp) Method

FindFile() public method

Tries to locate the given file.
public FindFile ( string path, string fileName, bool subfolders ) : StoreFile
path string The folder from where to start searching.
fileName string Name of the file.
subfolders bool Search in subfolders.
return StoreFile
        public StoreFile FindFile(string path, string fileName, bool subfolders)
        {
            StoreFolder folder = GetFolder(path);

            if(folder != null) {
                // check the files
                int length = folder.Files.Keys.Count;
                IList<string> keys = folder.Files.Keys;

                for(int i = 0; i < length; i++) {
                    if(keys[i] == fileName) {
                        return files[folder.Files[fileName]];
                    }
                }

                // check in subfolders
                if(subfolders) {
                    length = folder.Subfolders.Keys.Count;
                    keys = folder.Subfolders.Keys;

                    for(int i = 0; i < length; i++) {
                        StoreFile file = FindFile(path + "\\" + folder.Name, fileName, subfolders);

                        if(file != null) {
                            // file found, stop searching
                            return file;
                        }
                    }
                }
            }

            // nothing found
            return null;
        }