C# 获取函数以了解文件在文件夹中的插入

C# 获取函数以了解文件在文件夹中的插入,c#,C#,在C#中,如何知道文件已插入文件夹。我在C#中需要它。使用FileSystemWatcher类来完成此任务 请参阅 您可以使用System.IO命名空间中file类的exists方法确定指定的文件是否存在: bool System.IO.File.Exists(string path) 例如: using System; using System.IO; class Program { static void Main() { // See if this file

在C#中,如何知道文件已插入文件夹。我在C#中需要它。

使用FileSystemWatcher类来完成此任务

请参阅


您可以使用System.IO命名空间中file类的exists方法确定指定的文件是否存在:

bool System.IO.File.Exists(string path)
例如:

using System;
using System.IO;

class Program
{
    static void Main()
    {
    // See if this file exists in the SAME DIRECTORY.
    if (File.Exists("TextFile1.txt"))
    {
        Console.WriteLine("The file exists.");
    }
    // See if this file exists in the C:\ directory. [Note the @]
    if (File.Exists(@"C:\tidy.exe"))
    {
        Console.WriteLine("The file exists.");
    }
    // See if this file exists in the C:\ directory [Note the '\\' part]
    bool exists = File.Exists("C:\\lost.txt");
    Console.WriteLine(exists);
    }
}

如果要跟踪文件已由其他应用程序添加的事实,请搜索FileSystemWatcher。但其中存在着某些复杂性。阅读这个问题: