using System;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FolderContents
{
public class FolderContents : INotifyPropertyChanged
{
private string fldrPath = "";
private string fldrPath2 = "";
private string[] fldrFiles;
private string allowedExtensions = "";
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged(String info)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(info));
}
}
public string FolderPath
{
get
{
return this.fldrPath;
}
set
{
this.fldrPath = value;
NotifyPropertyChanged("FolderPath");
RefreshFolderFiles();
}
}
public string FolderPath2
{
get
{
return this.fldrPath2;
}
set
{
this.fldrPath2 = value;
NotifyPropertyChanged("FolderPath2");
RefreshFolderFiles();
}
}
public string AllowedExtensions
{
get
{
return this.allowedExtensions;
}
set
{
this.allowedExtensions = value;
NotifyPropertyChanged("AllowedExtensions");
RefreshFolderFiles();
}
}
public string[] FolderFiles
{
get
{
return this.fldrFiles;
}
set
{
}
}
public void RefreshFolderFiles()
{
List<string> files = new List<string>();
if (Directory.Exists(this.fldrPath))
{
if (this.allowedExtensions == "")
{
files.AddRange(Directory.GetFiles(this.fldrPath));
} else
{
string[] filters = this.allowedExtensions.Split(new Char[] { ';' });
foreach (string filter in filters)
{
files.AddRange(Directory.GetFiles(this.fldrPath, filter));
}
}
}
if (Directory.Exists(this.fldrPath2))
{
if (this.allowedExtensions == "")
{
files.AddRange(Directory.GetFiles(this.fldrPath2));
}
else
{
string[] filters = this.allowedExtensions.Split(new Char[] { ';' });
foreach (string filter in filters)
{
files.AddRange(Directory.GetFiles(this.fldrPath2, filter));
}
}
}
List<string> orderedfiles = new List<string>();
orderedfiles.AddRange(files.OrderByDescending(d => new FileInfo(d).CreationTime));
this.fldrFiles = orderedfiles.ToArray();
NotifyPropertyChanged("FolderFiles");
}
}
}