2014-10-13 2 views
1

사용자가 연 파일을 추적하고 하나의 특정 확장명으로 파일을 선택하려고합니다. 열린 파일에 해당 확장명이 있으면 추가 처리를 위해 파일 경로를 변수에 할당하려고합니다. 예제 응용 프로그램은 매우 많은 CPU를 요구합니다. 그렇게하기위한 쉽고 효율적인 방법이 있습니까?특정 확장명의 파일 추적

+0

http://stackoverflow.com/questions/14779616/filesystemwatcher-used-to-watch-for-folder-file-open/14779729#14779729 읽어보기 –

+0

나는 그것을 보았습니다. 특정 폴더를 찾지 만 전체 시스템, 특히 플래시 드라이브를보고 싶습니다. 또한 마지막 답변은 C++을 제안합니다. C#을 사용하고 싶습니다. – m1clee

+0

아마도 전체 시스템을 모니터링하는 대신 .ppt/.pptx 파일을 응용 프로그램과 연결할 수 있습니다. 그것은 훨씬 간단하게 들린다. –

답변

2

파일 -> 열린 이벤트 (네트워크 드라이브, 썸 드라이브 등)를 시스템 전체에서 모니터링하려면 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); 
     } 
    } 
} 

희망이 있습니다.

+0

이름이 "Public MainWindow()"인 기본 WPF 함수를 "static void Main (strings [] args)"으로 변경하면 오류가 발생합니다. 다른 것으로 변경하면 함수가 시작되지 않습니다. – m1clee

+0

새 WPF 응용 프로그램을 만들고 생성 된 파일 (App.config, App.xaml, App.xaml.cs, MainWindow.xaml 및 MainWindow.xaml.cs)을 삭제합니다. 그런 다음 'MainWindow'라는 새 클래스를 추가하고 생성 된 코드를 모두 지 웁니다. 위의 코드를 붙여 넣으면 컴파일됩니다. 경로를 수정하고 테스트를 시작하십시오. (나는 게시물을 만들기 전에 그것을 테스트했다) – Jeff

+0

@ m1clee - 나는 당신을 위해 일해서 다행이다. 행운을 빕니다. – Jeff

관련 문제