Как передать путь в метод?
public partial class clearTools : Form
{
static clearTools instance = null;
public clearTools()
{
InitializeComponent();
instance = this;
}
static void MonitorDesktop(string path)
{
FileSystemWatcher fileWatcher = new FileSystemWatcher();
fileWatcher.Path = path;
fileWatcher.Created += onDesktop;
fileWatcher.EnableRaisingEvents = true;
}
static void onDesktop(object sender, FileSystemEventArgs e)
{
FileInfo fi = new FileInfo(e.FullPath);
Console.WriteLine(fi.Extension);
if (fi.Extension == ".txt")
{
File.Move(e.FullPath, @$"{instance.imgPath.Text}\{e.Name}");
}
}
private void button1_Click(object sender, EventArgs e)
{
var desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
MonitorDesktop(desktopPath);
}
Ответы (1 шт):
Автор решения: aepot
→ Ссылка
static void onDesktop(object sender, FileSystemEventArgs e)
{
FileInfo fi = new FileInfo(e.FullPath);
Console.WriteLine(fi.Extension);
if (fi.Extension == ".txt")
{
string path = "";
instance.Invoke((Action)(() => path = instance.imgPath.Text));
File.Move(e.FullPath, @$"{path}\{e.Name}");
}
}