002
25.06.2004, 11:25 Uhr
aklaeser
|
OK! Sorry dann fürs falsche Forum!
Aber hier mal der ganze Code:
C++: |
// dirCon.cpp : Definiert den Einsprungpunkt für die Konsolenanwendung. // #include "stdafx.h" #define _WIN32_WINNT 0x0400
#include <afx.h>
#include <process.h> #include <afxmt.h> #include <AFXPRIV.H>
#include <Windows.h> #include <iostream>
using namespace std;
void Thread_Acc(void* arg); void Thread_Watch(void* arg);
//******************************************************************* //Hauptprogramm int main(int argc, char* argv[]) { int a;
FILE * ini; char str1[100]; CString str;
ini = fopen("C:\\dir.ini", "r");
int counter = 0;
while (!feof(ini)) { fscanf(ini, "%s\n", str1); printf("%s\n", str1); if (str1[0] != '[') { str = str1; str.Delete(0, 5);
_beginthread( Thread_Watch, 0, (void*)(LPCTSTR)str); _beginthread( Thread_Acc, 0, (void*)(LPCTSTR)str); counter++; //AfxMessageBox(str); } }
printf("%d\n", counter);
cin >> a; fclose(ini); //////////////////////////////////////////////////////////// return 0; }
//******************************************************************** //Funktion zum erkenn der Dateiverschiebungen void Thread_Watch(void* arg) { HANDLE file; CString str = (LPCTSTR)arg; file = FindFirstChangeNotification(str, TRUE, FILE_NOTIFY_CHANGE_FILE_NAME);
WaitForSingleObject(file, INFINITE);
while (true) { FindNextChangeNotification(file); WaitForSingleObject(file, INFINITE); }
FindCloseChangeNotification(file); }
//******************************************************************** //Erkennen welche Datei verändert wurde void Thread_Acc(void* arg) { USES_CONVERSION; CString str = (LPCTSTR)arg; AfxMessageBox(str); HANDLE hDir = CreateFile(str, FILE_LIST_DIRECTORY, FILE_SHARE_READ | FILE_SHARE_DELETE | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
FILE_NOTIFY_INFORMATION Buffer[1024]; DWORD BytesReturned; int i = 0;
while (ReadDirectoryChangesW(hDir, &Buffer, sizeof(Buffer), TRUE, FILE_NOTIFY_CHANGE_SECURITY | FILE_NOTIFY_CHANGE_CREATION | FILE_NOTIFY_CHANGE_LAST_ACCESS | FILE_NOTIFY_CHANGE_LAST_WRITE | FILE_NOTIFY_CHANGE_SIZE | FILE_NOTIFY_CHANGE_ATTRIBUTES | FILE_NOTIFY_CHANGE_DIR_NAME | FILE_NOTIFY_CHANGE_FILE_NAME, &BytesReturned, NULL, NULL)) { CString filename = ""; CString t_filename = "";
switch (Buffer[0].Action) { case FILE_ACTION_ADDED: filename = CString(Buffer[i].FileName).Left(Buffer[i].FileNameLength /2); //AfxMessageBox(filename); filename = str + "\\" + filename; printf("Datei hinzugefuegt oder geloescht\n");
t_filename = filename; t_filename.Delete(filename.GetLength() - 3, 3); //Kopie der Datei erstellen im selben Ordner die die richtigen Securityeisntellungen hat CopyFile(filename, t_filename, FALSE); //Original löschen DeleteFile(filename); //Kopie in Original umbenennen CopyFile(t_filename, filename, FALSE); //Kopie löschen DeleteFile(t_filename); break; case FILE_ACTION_REMOVED: filename = CString(Buffer[i].FileName).Left(Buffer[i].FileNameLength /2); //cout << "Datei entfernt" << endl; break; case FILE_ACTION_MODIFIED: filename = CString(Buffer[i].FileName).Left(Buffer[i].FileNameLength /2); //cout << "Attribute geaendert" << endl; break; } } }
|
und hier der Inhalt der Datei:
Code: |
[dir] pfad=C:\\test2 pfad=C:\\test
|
Hoffe das hilft Euch! |