Jump to content

ideas needed - how to read folder's deleted files info


 Share

Recommended Posts

Hello, I am about to create my own file sync utility but I wonder how to make its basic functionality - detect deleted files. How do google drive, dropbox and such things do it? I guess they have their own internal databases independent on file system right? One could say - just use robocopy with -mir parameter. But the problem of robocopy is, that is works one way only. You have to specify which folder is source and which is target. It considers source folder as a last state and mirrors the target folder according to source. But I want it to work both ways. That means that if I have two folders with photos and let's say I delete one photo in one folder and edit the same photo in another folder, I want my utility to recognize what change is most recent and sync according to that. For it I would like not only to know that the file is missing in one of the folder but also WHEN was it deleted. Because if it was deleted later then the modification date of the photo in first folder then I want the photo to be deleted from both. Anybody knows how it is usually done and if there is some best practice to handle this? Is it possible to read folder and find deleted file entries with date of deletion? I am not sure if this information is recorded in the folder at all...Maybe maintaining file list and comparing it with actual folder is the only options right? I guess WMI event handlers are also usually used to monitor folder changes, so point me to some tutorials if possible. Thank you.

Edited by LoWang
Link to comment
Share on other sites

One way I can see this working is to run a service or process that polls the folders contents periodically and logs the changes to it.

Another might be to use this File System Monitor UDF.

 

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

http://security.stackexchange.com/questions/61166/how-to-know-when-a-file-was-deleted-in-a-ntfs-filesystem

how about that? Do you think some common file sync/cloud software use NTFS journaling?

The easy way is to periodically check for changes as JohnOne says.

You should realize that what that post talks about is the USN change journal - not NTFS journaling.

If you really want to do it the hard way, you'll want to start with MSDN (https://msdn.microsoft.com/en-us/library/windows/desktop/aa363798(v=vs.85).aspx) and play with the API.

Link to comment
Share on other sites

rjframe what do you mean? I talk mainly about the first answer to that post. It contains some links and talks about ntfs journaling. Please be more clear with all those abbreviations and tell me what is USN ;)
BTW msdn link is broken :-\

Link to comment
Share on other sites

@LoWang

The NTFS journal (or log, or transaction journal) records changes to the volume; it's used to ensure data reliability and consistency, so you don't want to mess with it. I have never studied the NTFS format, so I cannot be more specific than that.

The USN Journal (update sequence number) records changes to directories, files, and streams, and can be monitored by applications via the API, documented at the link above.

Link to comment
Share on other sites

This is how I have figured out what you are trying to do and it works very well for me.

#include <FileConstants.au3>

Send("#m") ;~ this will minimize all open windows

$title = "Xternal Backup By Henry "
$Begtext = "Your Backup is about to commence" _
         & @LF & "Please save and close any open programs." _
         & @LF & "This program will start in 120 seconds."
$Fintext = "Your Backup has completed successfully !               "

$SourcePath = "<this would be the Source path where to copy your stuff to>"
$TargetPath = "<this would be the Target path where to copy your stuff to>"

;~ I also like to use
#NoTrayIcon ;~ hides the trayicon
Break(0) ;~ disables users ability to ctrl+break

;~ whats missing is a couple of these copy and paste it and add any apps that might be open like word or outlook
;~ Closes open programs
Local $MFF = ProcessExists("firefox.exe")
If $MFF Then ProcessClose($MFF)
Sleep(300)

$sm = MsgBox(65 + 262144, $title, $Begtext, 120)
If $sm = 2 Then Exit
If $sm = 1 Then
    $rc = RunWait("robocopy.exe" & " " & $SourcePath & " " & $TargetPath & "/e /eta /LOG+:e:\backup.log /tee")
Else
    $rc = RunWait("robocopy.exe" & " " & $SourcePath & " " & $TargetPath & "/e /eta /LOG+:e:\backup.log /tee")
    MsgBox(262144, $title, $Fintext, 60)
    Exit
EndIf
Break(1) ;~ turns off break
MsgBox(64, $title, $Fintext, 60)

 

 

shared backup.au3

Edited by Caiaphas
pasted code
Link to comment
Share on other sites

Link to comment
Share on other sites

Actually I am not really interested in some monitoring app which would have to be running. Imagine that google drive also may not be running but once you run it it somehow detects changes and syncs. So I guess this UDF will not work for the type of utility which would not have to be running continuously am I right? But I mayt test that anyway.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...