Hi all,
There are certain files (like doc, txt etc.) in a directory. I want to make an application which creates a back up of the files as soon as it has been closed after modification.
How can i approach that? Kindly Guide.
Printable View
Hi all,
There are certain files (like doc, txt etc.) in a directory. I want to make an application which creates a back up of the files as soon as it has been closed after modification.
How can i approach that? Kindly Guide.
Call CopyFile to copy the original file in a new one before saving the modifications.
This function will help to be notified of modification: FindFirstChangeNotification()
Quote:
Originally Posted by philkr
This notifies if any attributes are changed.I just want to know the files which aremodified & create their back up as soon as they are modified.Code:dwChangeHandles[0] = FindFirstChangeNotification (
"C:\\Test", // directory to watch
TRUE, // watch subtree
FILE_NOTIFY_CHANGE_ATTRIBUTES); // watch file attribute changes
Please Help
ReadDirectoryChangesW() can notify you of all sorts of directory changes - for example, changed attributes, files added, files deleted, files modified, files renamed etc. However, it only works with Windows XP and 2000 as far as I'm aware.
what exactly u want ? can u explain?
I want to be notified as soon as any file in a given directory is modified & then create its back up instantaneously.Quote:
Originally Posted by Gunaamirthavelu
FILE_NOTIFY_CHANGE_ATTRIBUTES is not the only flag you can pass to the function. FILE_NOTIFY_CHANGE_LAST_WRITE is what you need.Quote:
Originally Posted by erankushmehta
If your target platforms match its requirements you should check the ReadDirectoryChangesW function as well. This is a function to be used in conjunction with FindFirstChangeNotification. With it you can pinpoint the changes occuring in a directory.
You can find a sample of its usage here: MSDN - fwatch
Another example is CodeProject - Directory Change Watcher
Thanks, i get the notification.Now how to get the filename which was modified so that its back up may be created..Quote:
Originally Posted by PadexArt
This information has been provided already. Read the posts to their full extent and follow the links.Quote:
Originally Posted by erankushmehta
ReadDirectoryChanges & FILE_NOTIFY_INFORMATION will do. But i am not able to comprehend the complex parameters & getting the relevant info from the file notify structure.
Follow PadexArt's link to the directory change watcher. Everything is wrapped up with ready-made handlers for OnFileAdded(0, OnFileRemoved(), OnFileModified(), and OnFileNameChanged(). They don't come much easier than that.
i am getting following error:Code:if(!ReadDirectoryChangesW( pdi->m_hDir,
pdi->m_Buffer,//<--FILE_NOTIFY_INFORMATION records are put into this buffer
READ_DIR_CHANGE_BUFFER_SIZE,
pdi->m_bWatchSubDir,
pdi->m_dwChangeFilter,
&pdi->m_dwBufLength,//this var not set when using asynchronous mechanisms...
&pdi->m_Overlapped,
NULL))
I am using Windows 2000 Professional.Quote:
error C2065: 'ReadDirectoryChangesW' : undeclared identifier
Try putting the following line in one of your header files (preferably stdafx.h )
Code:#define _WIN32_WINNT 0x400
tried..but to no avail...Quote:
Originally Posted by John E
Plz help.
1) Comment out that line in whichever file you put it (stdafx.h ?)Code:#define _WIN32_WINNT 0x400
2) Put the same line right at the top of any source file that calls ReadDirectoryChangesW().
3) Save both files.
4) Re-compile the module that now contains the above #define (don't re-compile the whole project - just that one source file).
Do you still get the same error?
yeah...
Can you zip up that module (and its header file) and post them here as an attachment?
One other question - what version of Visual C++ are you using?Quote:
Originally Posted by erankushmehta
I am using VC++ 6.0.
Actually i am trying to use a wrapper class whose source code i have taken from the following link.
http://www.codeproject.com/file/dire...ngewatcher.asp
I have yet to add my code.
Anyway, just take the attachement as well.
Please Help..I have attached the code above..Quote:
Originally Posted by erankushmehta
Help....Plz..Quote:
Originally Posted by erankushmehta
Please Help..
The only obvious thing I could see was that you hadn't included the line that I suggested:-
As soon as I did that, the 'undeclared identifier' error went away.Code:#define _WIN32_WINNT 0x400
Anyway, I've revised your program to make better use of Wes Jones's Directory Change Watcher. If you run the attached app, it will start watching the folder C:\Program Files - then, after about 5 seconds, it will stop watching the folder. In both cases, a suitable message will be displayed in your console window.
Unfortunately, I didn't have time to figure out a way to get any changes notified (e.g. a file being added) since this would mean keeping the console open, without it being in a loop of some sort. Good luck with the rest of it... :wave:
Thanks John..actually i tried the same..i wonder how couldn't i resolve the error(i must have done somthing really silly)...anyway thanks a lot dear.. :wave:
Well, upto now i have been able to get the names of files as soon as these are modified.Quote:
Originally Posted by ovidiucucu
Now, i want to make different versions of the file each time it is modified.
I am following the approach below.Please guide is it the right way:
1) Suppose as soon as i open a.txt, its copy ~$a.txt is created.
2) If we close without saving ~$a.txt is deleted & original a.txt remains as such.
3) However, if we click save, a version of file, say a1, should be created. Next time, if save is clicked a2 should be created.
4) After the file is closed, a.txt should be deleted & ~$a.txt should be renamed to a.txt.
Having mentioned above 4 points, how can i get the notification that a file has been closed.
Kindly Guide.
Regards,
Ankush
Upto now i have managed to get the filenames of modified files & create their copies with new names being formed after suffixing time in seconds to their original name.
i am watching a directory(say, C:\Temp) & making copies of modified files in the same directory.
The Problem: As soon as i make a copy of a modified file, this copy creates its own copy and the chain reaction is triggered.It seems addition of file to the directory( or making a copy) is considered as modification.Is it the case here?
1. Kindly Guide how to resolve this
2. Do i necessarily need to have a separate back up directory to avoid this conflict?(However, asper requirement i can't do this).