跟踪特定扩展名的文件
本文关键字:文件 扩展名 跟踪 | 更新日期: 2023-09-27 18:26:24
我想跟踪用户打开的文件,并通过一个特定的扩展名选择它们。如果打开的文件具有该扩展名,那么我想将其文件路径分配给一个变量以供进一步处理。示例应用程序对cpu的要求非常高。有没有一种简单有效的方法可以做到这一点?
文件-->打开事件(包括网络驱动器、拇指驱动器等)的系统范围监控需要编写FS筛选器驱动程序。
由于您可以访问机器,并且肯定需要全系统访问,因此您可以简单地编写一个与Powerpoint扩展相关联的简单应用程序,执行复制,然后使用文件路径作为命令行参数打开Powerpoint。它看起来类似于以下内容:
using System;
using System.Windows;
using System.Diagnostics;
using System.IO;
namespace WpfApplication1
{
internal class MainWindow : Window
{
public MainWindow()
{ }
[STAThread()]
static void Main(string[] args)
{
if (args.Length == 0)
{
// [ show error or print usage ]
return;
}
if (!File.Exists(args[0]))
{
// [ show error or print usage ]
return;
}
// Perform the copy
FileInfo target = new FileInfo(args[0]);
string destinationFilename = string.Format("X:''ExistingFolder''{0}", target.Name);
File.Copy(target.FullName, destinationFilename);
// You may need to place the filename in quotes if it contains spaces
string targetPath = string.Format("'"{0}'"", target.FullName);
string powerpointPath = "[FullPathToPowerpointExecutable]";
Process powerpointInstance = Process.Start(powerpointPath, targetPath);
// This solution is using a wpf windows app to avoid
// the flash of the console window. However if you did
// wish to display an accumulated list then you may choose
// to uncomment the following block to display your UI.
/*
Application app = new Application();
app.MainWindow = new MainWindow();
app.MainWindow.ShowDialog();
app.Shutdown(0);
*/
Environment.Exit(0);
}
}
}
希望这能有所帮助。