gpt4 book ai didi

c# - FileWatcher 2 目录

转载 作者:太空宇宙 更新时间:2023-11-03 13:41:10 25 4
gpt4 key购买 nike

我制作了一个 FileWatcher,但我的 FileWatcher 没有按计划工作,我卡住了。

我想要一个可以处理 2 个 map 的文件观察器。

我自己做的代码不会选择我说他应该选择的路径。

在我的应用程序中,我需要浏览到一个位置,他需要检查该位置的文件发生了什么。

我的问题是:当我浏览时,它不会观看我选择的 map 。

我想他在我选择道路之前就已经看到了。

请帮忙。

(我刚开始第一次使用 C#)

如果有人想帮助我但没有足够的信息。

(实际上我还有 2 个文件,但这个看起来最好)

代码:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{

public Form1()

{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{

}

private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{


}

private void fileSystemWatcher1_Created(object sender, System.IO.FileSystemEventArgs e)
{
listBox1.Items.Add("File Created> " + e.FullPath + " -Date:" + DateTime.Now);
}

private void fileSystemWatcher1_Changed(object sender, System.IO.FileSystemEventArgs e)
{
listBox1.Items.Add("File Changed> " + e.FullPath + " -Date:" + DateTime.Now);
}
private void fileSystemWatcher1_Deleted(object sender, System.IO.FileSystemEventArgs e)
{

listBox1.Items.Add("File Deleted> " + e.FullPath + " -Date:" + DateTime.Now);

}

private void fileSystemWatcher1_Renamed(object sender, System.IO.RenamedEventArgs e)
{

listBox1.Items.Add("File Renamed> " + e.FullPath + " -Date:" + DateTime.Now);

}

private void fileSystemWatcher2_Changed(object sender, System.IO.FileSystemEventArgs e)
{
listBox1.Items.Add("File Changed> " + e.FullPath + " -Date:" + DateTime.Now);

}

private void fileSystemWatcher2_Created(object sender, System.IO.FileSystemEventArgs e)
{
listBox1.Items.Add("File Created> " + e.FullPath + " -Date:" + DateTime.Now);
}

private void fileSystemWatcher2_Deleted(object sender, System.IO.FileSystemEventArgs e)
{
listBox1.Items.Add("File Deleted> " + e.FullPath + " -Date:" + DateTime.Now);
}

private void fileSystemWatcher2_Renamed(object sender, System.IO.RenamedEventArgs e)
{
listBox1.Items.Add("File Renamed> " + e.FullPath + " -Date:" + DateTime.Now);
}

private void button2_Click(object sender, EventArgs e)
{
//
DialogResult resDialog = dlgOpenDir.ShowDialog();
if (resDialog.ToString() == "OK")
{
textBox1.Text = dlgOpenDir.SelectedPath;
}
}

private void button3_Click(object sender, EventArgs e)
{
DialogResult resDialog = dlgOpenDir.ShowDialog();
if (resDialog.ToString() == "OK")
{
textBox2.Text = dlgOpenDir.SelectedPath;
}
}

}
}

谢谢

最佳答案

第一个问题是您从未设置fileSystemWatcher1Path,因此在单击其中一个按钮时,在您返回路径后,执行以下操作:

fileSystemWatcher1.Path = dlgOpenDir.SelectedPath;

但是,您的下一个问题是您想要使用一个 FileSystemWatcher 来监视两个 路径,这是不可能的,您需要第二个一个观看两个。但是,它们可以使用相同的事件处理程序。所以一旦你有了第二个,在另一个按钮中点击你还没有使用过的,添加这个:

fileSystemWatcher2.Path = dlgOpenDir.SelectedPath;

关于c# - FileWatcher 2 目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16962246/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com