I want to find a change for a file, if the file changes, then I use a child_process to add a To copy the scp command, I will use a file on a server. I node See the JS documentation; fs.watchfile function I think what I want to do, but when I try to do this, in some way it just does not work as much as I expected the following code was used:
var fs = need ('fs'); Console.log ("watching .bash_profile"); Fs.watchfile ('/ home / test / .bash_profile', function (curr, prev) {console.log ("current meeting:" + curr.mtime); console.log ("previous match:" + prev.mtime) ; If (curr.mtime == prev.mtime) {console.log ("mtime equivalent");} and {console.log ("mtime not equal");}}); With the above code, if I use the file I've seen, the callback function is executed, it will produce the same time, and always output "Meat equal" (I only access the file). Output: Viewing .bash_profile Current Meet: Mon September 27 2010 18:41:27 GMT + 0100 (BST) Previous Day: Mon 27 Sep 2010 18:41:27 GMT + 0100 (BST) MTM is not equal
Anyone know if the statement failed (also tried using the probe === identity, but still receiving the same output) two meats one Why is that?
If the mtime
property is the date
objects, So this can never be equal to two different objects in javascript if they are actually the same objects (variables are pointing at the same memory frequency)
obj1 = New date (2010,0 9, 27); Obj2 = new date (2010,0 9, 27); Obj3 = obj1; // objects are passed from context! Obj1! = Obj2; // True, different object examples obj1 == obj3; // True, the two variable indicators are set to obj2 the same object! = Obj3; // True, different object examples
To check that these two date values are the same, use
curr.mtime.getTime () = = Prev .mtime.getTime ();
(I'm not sure that this is the case because I did not know that if watchfile
outputs the date objects or strings, but it certainly does not Your description seems like)
Comments
Post a Comment