@Unix-Tom



  • hi,
    du schriebst mir in einem Thread, das ich mit FindFirstCahngeNotification (oder so) das besser machen kann, ok hab ich gemacht, und klappt auch super!

    Aber kann ich denn auch damit gleichzeitig festellen welche Datei geändert worden ist?
    Ich habe nix passendes gefunden...

    Mein Code:

    HANDLE hFile=FindFirstCahngeNotification(pfad,TRUE,FILE_NOTIFY_CHANGE_LAST_WRITE);
    for(;;)
    {
         DWORD dwRet=WaitForSingleObject(hFile,INFINITE);
         if(dwRet==WAIT_OBJECT_0)
         {
              //todo
         }
         FindNextChangeNotification(hFile);
    }
    FindCloseChangeNotification(hFile);
    

    Thx for helping



  • Schau dir doch einfach das Beispiel an was dazu ist.
    Dort wird auch beschrieben das wenn man die Veränderung haben will den jeweiligen Ordner neu einlesen muss bzw. den Verzeichnisbaum...



  • Wo hast du das ein Beispiel? bin ich blind??



  • Vlt is deine Version zu alt...

    For an example, see Monitoring Changes in a Directory or Directory Tree.

    -------------------------

    Monitoring Changes in a Directory or Directory Tree
    The following example monitors the directory tree starting at C:\ for directory name changes. It also monitors the C:\WINDOWS directory for file name changes.

    The example uses the FindFirstChangeNotification function to create two notification handles and the WaitForMultipleObjects function to wait on the handles. Whenever a directory is created or deleted in the tree starting at C:\ , the example updates the entire directory tree. Whenever a file is created or deleted in the C:\WINDOWS directory, the example refreshes the WINDOWS directory. The FindNextChangeNotification function restarts the change notification each time the example processes a change.

    DWORD dwWaitStatus; 
    HANDLE dwChangeHandles[2]; 
    
    // Watch the C:\WINDOWS directory for file creation and 
    // deletion. 
    
    dwChangeHandles[0] = FindFirstChangeNotification( 
        "C:\\WINDOWS",                 // directory to watch 
        FALSE,                         // do not watch the subtree 
        FILE_NOTIFY_CHANGE_FILE_NAME); // watch file name changes 
    
    if (dwChangeHandles[0] == INVALID_HANDLE_VALUE) 
        ExitProcess(GetLastError()); 
    
    // Watch the C:\ subtree for directory creation and 
    // deletion. 
    
    dwChangeHandles[1] = FindFirstChangeNotification( 
        "C:\\",                        // directory to watch 
        TRUE,                          // watch the subtree 
        FILE_NOTIFY_CHANGE_DIR_NAME);  // watch dir. name changes 
    
    if (dwChangeHandles[1] == INVALID_HANDLE_VALUE) 
        ExitProcess(GetLastError()); 
    
    // Change notification is set. Now wait on both notification 
    // handles and refresh accordingly. 
    
    while (TRUE) 
    { 
    
        // Wait for notification.
    
        dwWaitStatus = WaitForMultipleObjects(2, dwChangeHandles, 
            FALSE, INFINITE); 
    
        switch (dwWaitStatus) 
        { 
            case WAIT_OBJECT_0: 
    
            // A file was created or deleted in C:\WINDOWS. 
            // Refresh this directory and restart the 
            // change notification. RefreshDirectory is an 
            // application-defined function. 
    
                RefreshDirectory("C:\\WINDOWS") 
                if ( FindNextChangeNotification( 
                        dwChangeHandles[0]) == FALSE ) 
                    ExitProcess(GetLastError()); 
                break; 
    
            case WAIT_OBJECT_0 + 1: 
    
            // A directory was created or deleted in C:\. 
            // Refresh the directory tree and restart the 
            // change notification. RefreshTree is an 
            // application-defined function. 
    
                RefreshTree("C:\\"); 
                if (FindNextChangeNotification( 
                        dwChangeHandles[1]) == FALSE) 
                    ExitProcess(GetLastError()); 
                break; 
    
            default: 
                ExitProcess(GetLastError()); 
        } 
    }
    


  • Ja und?
    Wie bekomme ich den jetzt heraus "welche" Datei geändert worden ist?
    Das er jedesmal erkennt das eine Datei geändert worden ist hab ich ja schon (code oben)

    Aber aus dem Code geht doch auch nicht hervor wie ich die geänderte File bekomme...



  • // A file was created or deleted in C:\WINDOWS.
    // Refresh this directory and restart the
    // change notification. RefreshDirectory is an
    // application-defined function.
    RefreshDirectory("C:\\WINDOWS");

    Du musst dir Selber eine Fkt. schreiben.
    Nimm halt ne Liste in die alle Dateinamen + Filetime reinkommen. Dann überprüfst bei welchen Dateien sich die Filetime geändert hat...

    Existiert die Datei nicht mehr wurde sie gelöscht, wenn alles noch stimmt dann wurde eine neue Datei angelegt...

    [ Dieser Beitrag wurde am 12.09.2002 um 17:41 Uhr von Nemesyzz editiert. ]



  • Ne. Als ich mit der Funktion experimentierte habe ich auch nichts gefunden.
    Habe dann inen eine map eingelesen und verglichen.
    Da du aber nur einen Datei überwachen wolltest sollte das ja kein Problem sein. Filedatum speicher und danach kontrolieren ob es diese Datei betroffen hat da du ja andere Dateien in dem Ordner ebenfalls überwacht werden.
    Ist jedenfalls beser als ne Schleife auf die Datei da ja nicht eine Programm etwas im Ordner macht sondern der Windowskernel und dieser liefert die einfach gesagt auch die Notifymessage.
    .



  • naja, das hat sich jetzt geändert, muss mehr files überwachen...werd mir da (oder hab ich schon halb) ne funktion zusammenbasteln...
    Trotzdem danke...


Anmelden zum Antworten