/// <summary> /// Populates a combobox with scraper groups /// </summary> /// <param name="cmbScraperGroupList">The combobox.</param> /// <returns>Scraper group list</returns> public static BindingList <string> GetScraperGroupsOnDisk(ComboBoxEdit cmbScraperGroupList) { var list = new BindingList <string>(); string path = Get.FileSystemPaths.PathDirScraperGroupsMovies; try { cmbScraperGroupList.Properties.Items.Clear(); string[] scraperGroupList = FastDirectoryEnumerator.EnumarateFilesPathList( Get.FileSystemPaths.PathDirScraperGroupsMovies, "*.xml"); foreach (string f in scraperGroupList) { cmbScraperGroupList.Properties.Items.Add(Path.GetFileNameWithoutExtension(f)); list.Add(Path.GetFileNameWithoutExtension(f)); } } catch (Exception ex) { Log.WriteToLog( LogSeverity.Error, 0, "Could not load scrapers from disk", path + Environment.NewLine + ex.Message); } return(list); }
/// <summary> /// Deletes the directory. /// </summary> /// <param name="target_dir"> /// The target_dir. /// </param> public static void DeleteDirectory(string target_dir) { try { string[] files = FastDirectoryEnumerator.EnumarateFilesPathList(target_dir); string[] dirs = Directory.GetDirectories(target_dir); foreach (string file in files) { File.SetAttributes(file, FileAttributes.Normal); File.Delete(file); } foreach (string dir in dirs) { DeleteDirectory(dir); } Directory.Delete(target_dir, false); } catch (Exception ex) { Log.WriteToLog(LogSeverity.Warning, 0, "Could not remove " + target_dir, ex.Message); } }
/// <summary> /// Removes all files in folder. /// </summary> /// <param name="path"> /// The path of which to remove all files /// </param> public static void RemoveAllFilesInFolder(string path) { string[] files = FastDirectoryEnumerator.EnumarateFilesPathList(path); foreach (string file in files) { File.Delete(file); } }
/// <summary> /// BGWs the do work. /// </summary> /// <param name="sender"> /// The sender. /// </param> /// <param name="e"> /// The <see cref="System.ComponentModel.DoWorkEventArgs"/> instance containing the event data. /// </param> private static void BgwDoWork(object sender, DoWorkEventArgs e) { var mediaPathModel = e.Argument as MediaPathModel; string[] files = FastDirectoryEnumerator.EnumarateFilesPathList( mediaPathModel.MediaPath, "*.*", SearchOption.AllDirectories); var returnCollection = new List <object>(2) { mediaPathModel, files }; e.Result = returnCollection; importInProgress = false; }
/// <summary> /// Returns the total file size of a folder. /// </summary> /// <param name="path"> /// The file path. /// </param> /// <param name="pattern"> /// The pattern. /// </param> /// <returns> /// The get directory size. /// </returns> public static long GetDirectorySize(string path, string pattern = "*.*") { const string LogCatagory = "IO > Info > GetDirectorySize"; try { if (string.IsNullOrEmpty(path) || !File.Exists(path)) { return(0); } path = path.Replace(Path.GetFileName(path), string.Empty); string[] a = FastDirectoryEnumerator.EnumarateFilesPathList(path, pattern); return(a.Select(name => new FileInfo(name)).Select(info => info.Length).Sum()); } catch (Exception ex) { Log.WriteToLog(LogSeverity.Error, LoggerName.GeneralLog, LogCatagory, ex.Message); } return(0); }
/// <summary> /// The find all files in a path /// </summary> /// <param name="path">The files path.</param> /// <param name="type">The SearchOption type.</param> /// <returns>All files in the path</returns> public static string[] FindAll(string path, SearchOption type) { return(FastDirectoryEnumerator.EnumarateFilesPathList(path, "*.*").ToArray()); }