C#
//Seleziono tutti i file
FileSystemWatcher FswVerificaCartella = new("C:\\Varie\\", "*.*");
C#
//tipo di notifica
FswVerificaCartella.NotifyFilter =
NotifyFilters.LastWrite
| NotifyFilters.CreationTime
| NotifyFilters.FileName
| NotifyFilters.DirectoryName
| NotifyFilters.Attributes
| NotifyFilters.Size
| NotifyFilters.LastWrite
| NotifyFilters.LastAccess
| NotifyFilters.CreationTime
| NotifyFilters.Security;
//Gestione eventi
FswVerificaCartella.Changed +=
FswVerificaCartella_Changed;
FswVerificaCartella.Created +=
FswVerificaCartella_Created;
FswVerificaCartella.Deleted +=
FswVerificaCartella_Deleted;
FswVerificaCartella.Error += FswVerificaCartella_Error;
FswVerificaCartella.Renamed +=
FswVerificaCartella_Renamed;
//Includere sottodirettory
FswVerificaCartella.IncludeSubdirectories = true;
//gestione eventi
FswVerificaCartella.EnableRaisingEvents
= true;
C#
public Form1()
{
try
{
//tipo di
notifica
FswVerificaCartella.NotifyFilter
= NotifyFilters.LastWrite
|
NotifyFilters.CreationTime
| NotifyFilters.FileName
|
NotifyFilters.DirectoryName
| NotifyFilters.Attributes
| NotifyFilters.Size
| NotifyFilters.LastWrite
| NotifyFilters.LastAccess
| NotifyFilters.CreationTime |
NotifyFilters.Security;
//Gestione eventi
FswVerificaCartella.Changed
+= FswVerificaCartella_Changed;
FswVerificaCartella.Created +=
FswVerificaCartella_Created;
FswVerificaCartella.Deleted +=
FswVerificaCartella_Deleted;
FswVerificaCartella.Error += FswVerificaCartella_Error;
FswVerificaCartella.Renamed +=
FswVerificaCartella_Renamed;
//Includere
sottodirettory
FswVerificaCartella.IncludeSubdirectories = true;
//gestione
eventi
FswVerificaCartella.EnableRaisingEvents = true;
//FswVerificaCartella.Filter
= "*.*";
}
catch (Exception ex)
{
MessageBox.Show("Errore: " + ex.Message);
}
InitializeComponent();
TxtLog.Text = "Esecuzione analizza cartella.";
}
C#
private void FswVerificaCartella_Renamed(object sender, RenamedEventArgs e)
{
TxtLog.Invoke(new Action(delegate ()
{
TxtLog.Text += "\r\n Rinominato";
TxtLog.Text += "\r\n Nome originario: " + e.OldName + " Percorso originario " + e.OldFullPath;
TxtLog.Text += "\r\n nuovo nome " + e.Name + " Nuovo percorso " + e.FullPath;
}));
}
C#
private void FswVerificaCartella_Error(object sender, ErrorEventArgs e)
{
TxtLog.Invoke(new Action(delegate ()
{
TxtLog.Text += "\r\n errore: " + e.GetException().Message;
}));
}
C#
private void FswVerificaCartella_Deleted(object sender,
FileSystemEventArgs e)
{
TxtLog.Invoke(new Action(delegate ()
{
TxtLog.Text += "\r\n cancellazione " + e.FullPath;
}));
}
C#
private void FswVerificaCartella_Created(object sender, FileSystemEventArgs e)
{
TxtLog.Invoke(new Action(delegate ()
{
TxtLog.Text += "\r\n creazione : " + e.FullPath + " " + e.Name;
}));
}
C#
private void FswVerificaCartella_Changed(object sender, FileSystemEventArgs
e)
{
if (e.ChangeType != WatcherChangeTypes.Changed)
return;
TxtLog.Invoke(new Action(delegate ()
{
TxtLog.Text += "\r\n" + "Cambiamento
" + e.FullPath;
}));
}
C#
public partial class Form1 : Form
{
//Seleziono tutti
i file
FileSystemWatcher FswVerificaCartella = new("C:\\Varie\\", "*.*");
public Form1()
{
try
{
//tipo di
notifica
FswVerificaCartella.NotifyFilter = NotifyFilters.LastWrite
|
NotifyFilters.CreationTime
| NotifyFilters.FileName
|
NotifyFilters.DirectoryName
| NotifyFilters.Attributes
| NotifyFilters.Size
| NotifyFilters.LastWrite
| NotifyFilters.LastAccess
| NotifyFilters.CreationTime |
NotifyFilters.Security;
//Gestione eventi
FswVerificaCartella.Changed
+= FswVerificaCartella_Changed;
FswVerificaCartella.Created +=
FswVerificaCartella_Created;
FswVerificaCartella.Deleted +=
FswVerificaCartella_Deleted;
FswVerificaCartella.Error +=
FswVerificaCartella_Error;
FswVerificaCartella.Renamed +=
FswVerificaCartella_Renamed;
//Includere
sottodirettory
FswVerificaCartella.IncludeSubdirectories = true;
//gestione
eventi
FswVerificaCartella.EnableRaisingEvents = true;
}
catch (Exception ex)
{
MessageBox.Show("Errore: " + ex.Message);
}
InitializeComponent();
TxtLog.Text = "Esecuzione analizza cartella.";
}
private void BtnEsegui_Click(object sender, EventArgs e)
{
}
private void FswVerificaCartella_Renamed(object sender, RenamedEventArgs e)
{
TxtLog.Invoke(new Action(delegate ()
{
TxtLog.Text += "\r\n Rinominato";
TxtLog.Text += "\r\n Nome originario: " + e.OldName + " Percorso originario " + e.OldFullPath;
TxtLog.Text += "\r\n nuovo nome " + e.Name + " Nuovo percorso " + e.FullPath;
}));
}
private void
FswVerificaCartella_Error(object sender,
ErrorEventArgs e)
{
TxtLog.Invoke(new Action(delegate ()
{
TxtLog.Text += "\r\n errore: " + e.GetException().Message;
}));
}
private void FswVerificaCartella_Deleted(object sender, FileSystemEventArgs e)
{
TxtLog.Invoke(new Action(delegate ()
{
TxtLog.Text += "\r\n cancellazione " + e.FullPath;
}));
}
private void FswVerificaCartella_Created(object sender, FileSystemEventArgs e)
{
TxtLog.Invoke(new Action(delegate ()
{
TxtLog.Text += "\r\n creazione : " + e.FullPath + " " + e.Name;
}));
}
private void FswVerificaCartella_Changed(object sender, FileSystemEventArgs e)
{
if (e.ChangeType != WatcherChangeTypes.Changed)
return;
TxtLog.Invoke(new Action(delegate ()
{
TxtLog.Text += "\r\n" + "Cambiamento
" + e.FullPath;
}));
}
}
Nessun commento:
Posta un commento