The problem is once a file is created it's displaying the file creation time in the Fsw_Created event but then also display that the file size has changed in the Fsw_Changed event.
I want somehow to make that if a file was created first time don't display any changes only after the file was created then if something changed in the file then display it in the Fsw_Changed event.
Maybe to remember some stuff in the Fsw_Created event for each file and then check for it in the Fsw_Changed event ?
I'm not sure how to solve it.
The created event :
private void Fsw_Created(object sender, FileSystemEventArgs e)
{
string time = DateTime.Now.ToString("h:mm:ss tt");
if (!richTextBoxLogChanges.Text.Contains(e.FullPath))
{
AppendText(richTextBoxLogChanges, $"File Name : {e.Name} ", Color.Red);
AppendText(richTextBoxLogChanges, $"Created At : {time}", Color.Yellow);
AppendText(richTextBoxLogChanges, "\n", Color.LightGreen);
}
}
The changed event :
private void Fsw_Changed(object sender, FileSystemEventArgs e)
{
if (e.ChangeType != WatcherChangeTypes.Changed)
{
return;
}
else
{
var info = new FileInfo(e.FullPath);
var theSize = info.Length;
var size = SizeSuffix(theSize);
string FileN1 = "File Name : ";
string FileN2 = info.Name;
string FileN3 = " Size Changed : ";
string FileN4 = size;
if (!richTextBoxLogChanges.Text.Contains(FileN1 + FileN2 + FileN3 + FileN4))
{
AppendText(richTextBoxLogChanges, FileN1, Color.Red);
AppendText(richTextBoxLogChanges, FileN2, Color.Yellow);
AppendText(richTextBoxLogChanges, FileN3, Color.Red);
AppendText(richTextBoxLogChanges, FileN4, Color.LightBlue);
AppendText(richTextBoxLogChanges, "\n", Color.LightGreen);
}
}
}