using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace RenameIt
{
///
/// List of Files in Folders.
///
internal class FilesInFolders
{
///
/// List of all Files.
///
public List GetFileArray { set; get; }
///
/// Creates a list which contains all filenames in a specific folder.
///
/// Folder which contains files to be listed.
/// True for scanning subfolders.
public FilesInFolders(string root, string extension, bool subFolders)
{
GetFileArray = GetFileList(root, extension, subFolders);
}
private List GetFileList(string root, string extension, bool subFolders)
{
List fileArray = new List();
try
{
string[] Files = System.IO.Directory.GetFiles(root);
string[] Folders = System.IO.Directory.GetDirectories(root);
for (int i = 0; i < Files.Length; i++)
{
if (extension == ".*" || extension == "" || Path.GetExtension(Files[i]) == extension)
{
fileArray.Add(Files[i].ToString());
}
}
if (subFolders == true)
{
for (int i = 0; i < Folders.Length; i++)
{
fileArray.AddRange(GetFileList(Folders[i], extension, subFolders));
}
}
}
catch (Exception Ex)
{
throw (Ex);
}
return fileArray;
}
}
}