CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 27
  1. #1
    Join Date
    Oct 2005
    Location
    Mumbai, India
    Posts
    425

    Back up of modified files

    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.

    Regards,
    Ankush Mehta

    "The Child is the father of the Man."
    William Wordsworth

  2. #2
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,244

    Re: Back up of modified files

    Call CopyFile to copy the original file in a new one before saving the modifications.
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

  3. #3
    Join Date
    Jul 2005
    Location
    Germany
    Posts
    1,194

    Re: Back up of modified files

    This function will help to be notified of modification: FindFirstChangeNotification()
    Please don't forget to rate users who helped you!

  4. #4
    Join Date
    Oct 2005
    Location
    Mumbai, India
    Posts
    425

    Re: Back up of modified files

    Quote Originally Posted by philkr
    This function will help to be notified of modification: FindFirstChangeNotification()
    Code:
    dwChangeHandles[0] = FindFirstChangeNotification  ( 
    "C:\\Test",                   // directory to watch 
    TRUE,                         // watch subtree 
    
    FILE_NOTIFY_CHANGE_ATTRIBUTES); // watch file attribute changes
    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.
    Please Help
    Last edited by erankushmehta; March 14th, 2006 at 04:41 AM.

    Regards,
    Ankush Mehta

    "The Child is the father of the Man."
    William Wordsworth

  5. #5
    John E is offline Elite Member Power Poster
    Join Date
    Apr 2001
    Location
    Manchester, England
    Posts
    4,867

    Re: Back up of modified files

    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.
    "A problem well stated is a problem half solved.” - Charles F. Kettering

  6. #6
    Join Date
    Jun 2005
    Location
    Tirunelveli-Tamil Nadu-India
    Posts
    354

    Smile Re: Back up of modified files

    what exactly u want ? can u explain?
    If I Helped You, "Rate This Post"

    Thanks
    Guna

  7. #7
    Join Date
    Oct 2005
    Location
    Mumbai, India
    Posts
    425

    Re: Back up of modified files

    Quote Originally Posted by Gunaamirthavelu
    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.

    Regards,
    Ankush Mehta

    "The Child is the father of the Man."
    William Wordsworth

  8. #8
    Join Date
    Aug 2002
    Location
    Cluj-Napoca,Romania
    Posts
    3,496

    Re: Back up of modified files

    Quote Originally Posted by erankushmehta
    FILE_NOTIFY_CHANGE_ATTRIBUTES); // watch file attribute changes [/CODE]

    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.
    Please Help
    FILE_NOTIFY_CHANGE_ATTRIBUTES is not the only flag you can pass to the function. FILE_NOTIFY_CHANGE_LAST_WRITE is what you need.

    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
    Har Har

  9. #9
    Join Date
    Oct 2005
    Location
    Mumbai, India
    Posts
    425

    Re: Back up of modified files

    Quote Originally Posted by PadexArt
    FILE_NOTIFY_CHANGE_ATTRIBUTES is not the only flag you can pass to the function. FILE_NOTIFY_CHANGE_LAST_WRITE is what you need.
    Thanks, i get the notification.Now how to get the filename which was modified so that its back up may be created..

    Regards,
    Ankush Mehta

    "The Child is the father of the Man."
    William Wordsworth

  10. #10
    Join Date
    Aug 2002
    Location
    Cluj-Napoca,Romania
    Posts
    3,496

    Thumbs down Re: Back up of modified files

    Quote Originally Posted by erankushmehta
    Thanks, i get the notification.Now how to get the filename which was modified so that its back up may be created..
    This information has been provided already. Read the posts to their full extent and follow the links.
    Har Har

  11. #11
    Join Date
    Oct 2005
    Location
    Mumbai, India
    Posts
    425

    Re: Back up of modified files

    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.

    Regards,
    Ankush Mehta

    "The Child is the father of the Man."
    William Wordsworth

  12. #12
    John E is offline Elite Member Power Poster
    Join Date
    Apr 2001
    Location
    Manchester, England
    Posts
    4,867

    Re: Back up of modified files

    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.
    "A problem well stated is a problem half solved.” - Charles F. Kettering

  13. #13
    Join Date
    Oct 2005
    Location
    Mumbai, India
    Posts
    425

    Re: Back up of modified files

    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 getting following error:
    error C2065: 'ReadDirectoryChangesW' : undeclared identifier
    I am using Windows 2000 Professional.

    Regards,
    Ankush Mehta

    "The Child is the father of the Man."
    William Wordsworth

  14. #14
    John E is offline Elite Member Power Poster
    Join Date
    Apr 2001
    Location
    Manchester, England
    Posts
    4,867

    Re: Back up of modified files

    Try putting the following line in one of your header files (preferably stdafx.h )

    Code:
    #define _WIN32_WINNT 0x400
    "A problem well stated is a problem half solved.” - Charles F. Kettering

  15. #15
    Join Date
    Oct 2005
    Location
    Mumbai, India
    Posts
    425

    Re: Back up of modified files

    Quote Originally Posted by John E
    Try putting the following line in one of your header files (preferably stdafx.h )

    Code:
    #define _WIN32_WINNT 0x400
    tried..but to no avail...

    Plz help.

    Regards,
    Ankush Mehta

    "The Child is the father of the Man."
    William Wordsworth

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured