using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using Template; namespace RenameIt { /// /// Counts the files in a directory. /// internal class AllFiles { string directory = ""; string extension = ".*"; bool subDir = false; /// /// Counts all files in a directory. /// /// This directory contains the files. /// If it is true, it will search in all subdirectories too. public AllFiles(string path, string extension, bool subDir) { this.directory = path; if (extension.StartsWith(".")) { this.extension = extension; } else { this.extension = "." + extension; } this.subDir = subDir; } /// /// Returns the number of files. /// /// public int Lenght() { DirectoryInfo di = new DirectoryInfo(directory); if (!subDir) { return di.GetFiles("*" + extension).Length; } else { return di.GetFiles("*" + extension, SearchOption.AllDirectories).Length; //Eins abziehen damit das Ergebnis richtig ist. } } /// /// Returns a list of all files. /// /// A list in string format. public List GetFileList() { //Dateiliste erstellen List fileList = new List(); try { FilesInFolders fif = new FilesInFolders(directory, extension, subDir); fileList = fif.GetFileArray; return fileList; } catch (Exception) { MessageBox.Show(AppResources.msg007, AppResources.capt001, MessageBoxButtons.OK); fileList.Clear(); return fileList; } } } }