83 lines
2.3 KiB
C#
83 lines
2.3 KiB
C#
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
|
|
{
|
|
/// <summary>
|
|
/// Counts the files in a directory.
|
|
/// </summary>
|
|
internal class AllFiles
|
|
{
|
|
string directory = "";
|
|
string extension = ".*";
|
|
bool subDir = false;
|
|
|
|
/// <summary>
|
|
/// Counts all files in a directory.
|
|
/// </summary>
|
|
/// <param name="path">This directory contains the files.</param>
|
|
/// <param name="subDir">If it is true, it will search in all subdirectories too.</param>
|
|
public AllFiles(string path, string extension, bool subDir)
|
|
{
|
|
this.directory = path;
|
|
|
|
if (extension.StartsWith("."))
|
|
{
|
|
this.extension = extension;
|
|
}
|
|
else
|
|
{
|
|
this.extension = "." + extension;
|
|
}
|
|
|
|
this.subDir = subDir;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Returns the number of files.
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
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.
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Returns a list of all files.
|
|
/// </summary>
|
|
/// <returns>A list in string format.</returns>
|
|
public List<string> GetFileList()
|
|
{
|
|
//Dateiliste erstellen
|
|
List<string> fileList = new List<string>();
|
|
|
|
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;
|
|
}
|
|
}
|
|
}
|
|
}
|