Ich habe eine Anwendung, die Verzeichnisse für Änderungen überwacht. Allerdings, wenn ich ein Verzeichnis umbenennen, kann in Verzeichnis B Verzeichnis A sagt, als ich die folgende Ausgabe Ergebnisse sehen:C++ ReadDirectoryChangesW und Boost gibt dir die Änderung als Datei (OLD NAME)
File renamed (OLD): C:\A
Directory renamed (NEW): C:\B
, während ich den Ausgang erwarten:
Directory renamed (OLD): C:\A
Directory renamed (NEW): C:\B
Diese Gelegenheit auch auftritt ein Verzeichnis auf Löschen, was die Ausgabe:
File removed: C:\A\test.txt
File modified: C:\A
File removed: C:\A
während ich erwarte, dass die Ausgabe:
File removed: C:\A\test.txt
Directory modified: C:\A
Directory removed: C:\A
Der Code, den ich auf diese Ausgabe erhalten verwenden (mit Boost-Dateisystem) ist:
while(true) {
FILE_NOTIFY_INFORMATION* info = reinterpret_cast<FILE_NOTIFY_INFORMATION*>(p);
int ret = ::WideCharToMultiByte(CP_ACP, 0, info->FileName, info->FileNameLength/sizeof(WCHAR), FilePathChar, sizeof(FilePathChar), NULL, NULL);
stringstream FilePathStream;
FilePathStream << argv[1];
FilePathStream << "\\";
FilePathStream << FilePathChar;
string FilePath = FilePathStream.str();
cout << FilePath << endl;
boost::filesystem::path path(FilePath);
string Type = "File";
if (boost::filesystem::is_directory(path)) {
Type = "Directory";
}
ofstream myfile;
myfile.open("changes.txt", std::ios_base::app);
switch (info->Action) {
case FILE_ACTION_ADDED:
myfile << Type << " added: " << FilePath << "\n";
break;
case FILE_ACTION_MODIFIED:
myfile << Type << " modified: " << FilePath << "\n";
break;
case FILE_ACTION_REMOVED:
myfile << Type << " removed: " << FilePath << "\n";
break;
case FILE_ACTION_RENAMED_NEW_NAME:
myfile << Type << " renamed (NEW): " << FilePath << "\n";
break;
case FILE_ACTION_RENAMED_OLD_NAME:
myfile << Type << " renamed (OLD): " << FilePath << "\n";
break;
default:
myfile << Type << " UNDISCOVERED ACTION: " << FilePath << "\n";
break;
}
myfile.close();
::memset(FilePathChar, '\0', sizeof(FilePathChar));
if (!info->NextEntryOffset) break;
p += info->NextEntryOffset;
}
Was mache ich falsch hier?
@HansPassant, wird es tatsächlich nicht. Wie die Dokumentation sagt, wird es den relativen Pfad aus dem überwachten Verzeichnis zurückgeben. –