2009-03-05 2 views
0

이제 남은 사람이 작성한 응용 프로그램이 몇 개 (또는 그 이상) 있습니다.이 응용 프로그램은이 개발자의 오래된 PC에 저장된 Microsoft Access 데이터베이스에 액세스합니다. 프로덕션 SQL 데이터베이스 이제 이러한 모든 프로그램을 추적하고 실행 시간을 알려주고 있습니다. 파일 액세스 시간의 로그를 유지하고 싶습니다. 가능합니까? 분명히 액세스 시간을 읽으면 수정할 것입니다. 일부 액세스 데이터베이스는 SQL 데이터베이스에 연결된 테이블이기 때문에 수정 된 시간에 의존 할 수 없습니다.파일 액세스 시간의 로그를 보관하십시오

C#에서 이렇게하는 것이 좋지만 중요하지 않습니다. 어디서 실행했는지 추적해야합니다. 찾았 으면 수정 될 수 있습니다.

감사합니다.

답변

1
http://msdn.microsoft.com/en-us/library/system.io.filesystemwatcher.aspx

public class Watcher 

{

public static void Main() 
{ 
Run(); 

} 

[PermissionSet(SecurityAction.Demand, Name="FullTrust")] 
public static void Run() 
{ 
    string[] args = System.Environment.GetCommandLineArgs(); 

    // If a directory is not specified, exit program. 
    if(args.Length != 2) 
    { 
     // Display the proper way to call the program. 
     Console.WriteLine("Usage: Watcher.exe (directory)"); 
     return; 
    } 

    // Create a new FileSystemWatcher and set its properties. 
    FileSystemWatcher watcher = new FileSystemWatcher(); 
    watcher.Path = args[1]; 
    /* Watch for changes in LastAccess and LastWrite times, and 
     the renaming of files or directories. */ 
    watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite 
     | NotifyFilters.FileName | NotifyFilters.DirectoryName; 
    // Only watch text files. 
    watcher.Filter = "*.txt"; 

    // Add event handlers. 
    watcher.Changed += new FileSystemEventHandler(OnChanged); 
    watcher.Created += new FileSystemEventHandler(OnChanged); 
    watcher.Deleted += new FileSystemEventHandler(OnChanged); 
    watcher.Renamed += new RenamedEventHandler(OnRenamed); 

    // Begin watching. 
    watcher.EnableRaisingEvents = true; 

    // Wait for the user to quit the program. 
    Console.WriteLine("Press \'q\' to quit the sample."); 
    while(Console.Read()!='q'); 
} 

// Define the event handlers. 
private static void OnChanged(object source, FileSystemEventArgs e) 
{ 
    // Specify what is done when a file is changed, created, or deleted. 
    Console.WriteLine("File: " + e.FullPath + " " + e.ChangeType); 
} 

private static void OnRenamed(object source, RenamedEventArgs e) 
{ 
    // Specify what is done when a file is renamed. 
    Console.WriteLine("File: {0} renamed to {1}", e.OldFullPath, e.FullPath); 
} 

}

관련 문제