I helped with the first part (archive the files into a folder). Let me know if it works.
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
void handleFiles(string folderPath, string prefix, List suffixes)
{
//create a folder with current date
string newFolderName = folderPath + "\\old_files\\" + DateTime.Now.ToString("yyyy_MM_dd_HH_mm_ss");
System.IO.Directory.CreateDirectory(newFolderName);
foreach (string suffix in suffixes)
{
string srcFilename = string.Format("{0}\\{1}_{2}", folderPath, prefix, suffix);
string dstFilename = string.Format("{0}\\{1}_{2}", newFolderName, prefix, suffix);
System.IO.File.Move(srcFilename, dstFilename);
}
//then handle the d file
//TODO
}
void checkFile(string folderPath)
{
string[] files = System.IO.Directory.GetFiles(folderPath);
Dictionary> dict = new Dictionary>();
foreach (string file in files)
{
string filename = System.IO.Path.GetFileName(file);
string[] parts = filename.Split(new char[] { '_' });
//parse the prefix
if (parts.Length == 2)
{
if (!dict.ContainsKey(parts[0]))
{
dict[parts[0]] = new List();
dict[parts[0]].Add(parts[1]);
}
else
{
dict[parts[0]].Add(parts[1]);
}
}
}
foreach (string key in dict.Keys)
{
//check if a.txt,b.txt,c.pdf,d.txt are all ready.
List suffixes = dict[key];
if (suffixes.Contains("a.txt") &&
suffixes.Contains("b.txt") &&
suffixes.Contains("c.pdf") &&
suffixes.Contains("d.txt"))
{
handleFiles(folderPath, key, suffixes);
}
}
}
private void button1_Click(object sender, EventArgs e)
{
//Put this into a timer, and you can have this program monitoring the src folder every several seconds.
checkFile("c:\\files");
}
}