61 lines
1.9 KiB
C#
61 lines
1.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace RenameIt
|
|
{
|
|
/// <summary>
|
|
/// List of Files in Folders.
|
|
/// </summary>
|
|
internal class FilesInFolders
|
|
{
|
|
/// <summary>
|
|
/// List of all Files.
|
|
/// </summary>
|
|
public List<string> GetFileArray { set; get; }
|
|
|
|
/// <summary>
|
|
/// Creates a list which contains all filenames in a specific folder.
|
|
/// </summary>
|
|
/// <param name="root">Folder which contains files to be listed.</param>
|
|
/// <param name="subFolders">True for scanning subfolders.</param>
|
|
public FilesInFolders(string root, string extension, bool subFolders)
|
|
{
|
|
GetFileArray = GetFileList(root, extension, subFolders);
|
|
}
|
|
|
|
private List<string> GetFileList(string root, string extension, bool subFolders)
|
|
{
|
|
List<string> fileArray = new List<string>();
|
|
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;
|
|
}
|
|
}
|
|
}
|