FileSystemWatcher 类
侦听文件系统更改通知,并在目录或目录中的文件发生更改时引发事件。ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.2052/cpref/html/frlrfsystemiofilesystemwatcherclasstopic.htm
侦听文件系统更改通知,并在目录或目录中的文件发生更改时引发事件。ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.2052/cpref/html/frlrfsystemiofilesystemwatcherclasstopic.htm
[Visual Basic]
Imports System
Imports System.IO
Imports Microsoft.VisualBasicPublic Class Test
Public Shared Sub Main()
' Specify the directory you want to manipulate.
Dim path As String = "c:\MyDir" Try
' Determine whether the directory exists.
If Directory.Exists(path) Then
Console.WriteLine("That path exists already.")
Return
End If ' Try to create the directory.
Dim di As DirectoryInfo = Directory.CreateDirectory(path)
Console.WriteLine("The directory was created successfully at {0}.", Directory.GetCreationTime(path)) ' Delete the directory.
di.Delete()
Console.WriteLine("The directory was deleted successfully.") Catch e As Exception
Console.WriteLine("The process failed: {0}.", e.ToString())
End Try
End Sub
End Class
[C#]
using System;
using System.IO;class Test
{
public static void Main()
{
// Specify the directory you want to manipulate.
string path = @"c:\MyDir"; try
{
// Determine whether the directory exists.
if (Directory.Exists(path))
{
Console.WriteLine("That path exists already.");
return;
} // Try to create the directory.
DirectoryInfo di = Directory.CreateDirectory(path);
Console.WriteLine("The directory was created successfully at {0}.", Directory.GetCreationTime(path)); // Delete the directory.
di.Delete();
Console.WriteLine("The directory was deleted successfully.");
}
catch (Exception e)
{
Console.WriteLine("The process failed: {0}", e.ToString());
}
finally {}
}
}