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 all directories in a directory.
|
|
/// </summary>
|
|
internal class AllDirectories
|
|
{
|
|
string directory = "";
|
|
bool subDir = false;
|
|
|
|
/// <summary>
|
|
/// Counts all directories in a directory.
|
|
/// </summary>
|
|
/// <param name="path">This directory contains the directories.</param>
|
|
public AllDirectories(string path)
|
|
{
|
|
this.directory = path;
|
|
this.subDir = false;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Counts all directories in a directory.
|
|
/// </summary>
|
|
/// <param name="path">This directory contains the directories.</param>
|
|
/// <param name="subDir">If it is true, it will search in all subdirectories too.</param>
|
|
public AllDirectories(string path, bool subDir)
|
|
{
|
|
this.directory = path;
|
|
this.subDir = subDir;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Returns the number of directories.
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public int Lenght()
|
|
{
|
|
DirectoryInfo di = new DirectoryInfo(directory);
|
|
|
|
if (!subDir)
|
|
{
|
|
return di.GetDirectories().Length;
|
|
}
|
|
else
|
|
{
|
|
return di.GetDirectories("*.*", SearchOption.AllDirectories).Length;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Returns a list of all direcrories.
|
|
/// </summary>
|
|
/// <returns>A list in string format.</returns>
|
|
public List<string> GetDirectoryList()
|
|
{
|
|
//Verzeichnisliste erstellen
|
|
List<string> directoryList = new List<string>();
|
|
|
|
try
|
|
{
|
|
DirectoriesInFolders dif = new DirectoriesInFolders(directory, subDir);
|
|
directoryList = dif.GetDirectoryArray;
|
|
return directoryList;
|
|
}
|
|
catch (Exception)
|
|
{
|
|
MessageBox.Show(AppResources.msg007, AppResources.capt001, MessageBoxButtons.OK);
|
|
directoryList.Clear();
|
|
return directoryList;
|
|
}
|
|
}
|
|
}
|
|
}
|