public static void scanDirectories() { try { tim_file = 0; tim_dir = 0; dirs_scanned = 0; files_scanned = 0; DateTime time_start = DateTime.Now; //if in cache mode, load the cache. try { if (useCache) { cache = new FileCache(); } } catch (Exception e) { throw new Exception("Error loading cache", e); } //add all files from our pathlist to a list List <string> folders = new List <string>(); try { foreach (DirectoryInfo d in PickRandomFile.folderList) { if (d.Exists) { try { folders.Add(d.FullName); } catch { MessageBox.Show("Directory didnt have a fullname?"); MessageBox.Show(d.Name); } //add all subfolders if (recurse) { foreach (DirectoryInfo di in d.GetDirectories("*", SearchOption.AllDirectories)) { if (di.Exists) { folders.Add(di.FullName); } } } } else if (!ignoreMissingFolders) { MessageBox.Show("Directory " + d.FullName + " doesnt exist"); } } tim_dir = DateTime.Now.Subtract(time_start).Seconds; } catch (Exception e) { throw new Exception("Error during directory sweep", e); } //Now check for files (or use cache where appropriate) try { foreach (String s in folders) { List <FileShortInfo> files = null; if (useCache) { files = cache.getFilesFromCache(s); } //get the files directly if we havent found them in the cache, or we arent using it if (files == null) { getFilesFromFolder(s); } else { try { foreach (FileShortInfo f in files) { if (addFileToResults(f)) { allFiles.Add(f); } } } catch (Exception e) { throw new Exception("Error transferring file to results object", e); } } } } catch (Exception e) { throw new Exception("Error scanning for files", e); } if (showCacheStats) { MessageBox.Show( "Total Time: " + DateTime.Now.Subtract(time_start).TotalSeconds.ToString() + "\n" + "Files " + files_scanned.ToString() + ", Directories " + dirs_scanned.ToString() + "\n" + "Files Added: " + allFiles.Count.ToString() + "\n" + "File Time: " + tim_file.ToString() + "\n" + "Dir Time: " + tim_dir.ToString() + (useCache ? "\n" + cache.getStats() : "") ); } if (useCache) { cache.saveCache(); } } catch (Exception e) { throw new Exception("Error during scanDirectories", e); } }
public static void scanDirectories() { try { tim_file = 0; tim_dir = 0; dirs_scanned = 0; files_scanned = 0; DateTime time_start = DateTime.Now; //if in cache mode, load the cache. try { if (useCache) { cache = new FileCache(); } } catch (Exception e) { throw new Exception("Error loading cache", e); } //add all files from our pathlist to a list List<string> folders = new List<string>(); try { foreach (DirectoryInfo d in PickRandomFile.folderList) { if (d.Exists) { try { folders.Add(d.FullName); } catch { MessageBox.Show("Directory didnt have a fullname?"); MessageBox.Show(d.Name); } //add all subfolders if (recurse) { foreach (DirectoryInfo di in d.GetDirectories("*", SearchOption.AllDirectories)) { if (di.Exists) { folders.Add(di.FullName); } } } } else { MessageBox.Show("Directory " + d.FullName + " doesnt exist"); } } tim_dir = DateTime.Now.Subtract(time_start).Seconds; } catch (Exception e) { throw new Exception("Error during directory sweep", e); } //Now check for files (or use cache where appropriate) try { foreach (String s in folders) { List<FileShortInfo> files = null; if (useCache) { files = cache.getFilesFromCache(s); } //get the files directly if we havent found them in the cache, or we arent using it if (files == null) { getFilesFromFolder(s); } else { try { foreach (FileShortInfo f in files) { if (addFileToResults(f)) { allFiles.Add(f); } } } catch (Exception e) { throw new Exception("Error transferring file to results object", e); } } } } catch (Exception e) { throw new Exception("Error scanning for files", e); } if (showCacheStats) { MessageBox.Show( "Total Time: " + DateTime.Now.Subtract(time_start).TotalSeconds.ToString() + "\n" + "Files " + files_scanned.ToString() + ", Directories " + dirs_scanned.ToString() + "\n" + "Files Added: " + allFiles.Count.ToString() + "\n" + "File Time: " + tim_file.ToString() + "\n" + "Dir Time: " + tim_dir.ToString() + (useCache ? "\n" + cache.getStats() : "") ); } if (useCache) { cache.saveCache(); } } catch (Exception e) { throw new Exception("Error during scanDirectories", e); } }