按下按钮,创建并打开文件夹,扫描它的文件
本文关键字:扫描 文件夹 文件 按钮 创建 | 更新日期: 2023-09-27 17:50:25
谁能帮我一个功能…我正在创建windows窗体应用程序,其中在某些按钮推动应用程序创建文件夹(在apps .exe根目录中),例如名为Folder1,创建后也打开它。
编辑:我已经这样做过了
private void button1_Click(object sender, EventArgs e)
{
System.IO.Directory.CreateDirectory("CPC Folder");
string myPath = @"CPC Folder";
System.Diagnostics.Process prc = new System.Diagnostics.Process();
prc.StartInfo.FileName = myPath;
prc.Start();
}
这是第一部分,在第二部分中,在用户将一个。txt文件放入该文件夹后,我需要扫描功能的帮助,该功能将扫描新创建的文件夹为用户输入。txt文件,当发现它保存路径到它的变量。
现在最主要的是第一部分。我可能会想办法完成第二件事……希望有人能帮助我:)
注。这个应用程序是基于c#和我的代码,我现在只能显示这个:
private void button1_Click(object sender, EventArgs e) { }
要完成第一部分,您需要的是以下代码:
Directory.CreateDirectory("SomeDirectoryName");
您需要查看这个类:FileSystemWatcher
链接
应该可以了
private string myTextFile;
private void button1_Click(object sender, EventArgs e)
{
string myPath = Environment.CurrentDirectory + @"'CPC Folder";
System.IO.Directory.CreateDirectory(myPath);
Process.Start("explorer.exe", myPath);
FileSystemWatcher fileWatcher = new FileSystemWatcher(myPath, "*.txt");
fileWatcher.EnableRaisingEvents = true;
fileWatcher.Created += (snder, eArgs) =>
{
myTextFile = eArgs.FullPath;
};
}