friends 0 Posted January 25, 2005 Hi all. Lately, I use FileGetTime() to trace if a file is been modified (Last modified). Below is the coding.... This script will be running in Win2K OS. However, I tested it out, there is a error message shown as attached. Please help me to find out where it goes wrong, I'm stuck already. $FilePath = "d:\store\dat\mitran.mdb" $BakFilePath = "d:\store\dat\mitran.bak" FileCopy ($FilePath, $BakFilePath, 1) ; Initial Copy of Mitran.bak WHILE 1 $OriFileTime = FileGetTime($FilePath) $OriHHMMSS = ($OriFileTime[3] - 12) & ":" & $OriFileTime[4] & ":" & $OriFileTime[5] $BakFileTime = FileGetTime($BakFilePath) $BakHHMMSS = ($BakFileTime[3] - 12) & ":" & $BakFileTime[4] & ":" & $OriFileTime[5] IF $BakHHMMSS <> $OriHHMMSS THEN FileCopy ($FilePath, $BakFilePath, 1) ENDIF WEND Share this post Link to post Share on other sites
tazdev 1 Posted January 25, 2005 It is working for me except it is stuck in the While Statement. Share this post Link to post Share on other sites
Domonoky 0 Posted January 25, 2005 (edited) Hi.. i think the problem is, if the FileGetTime() function has a failure, it returns numeric 1 and not an array. So if you use this as a Array, you get that error. So you have to check if the fileGetTime() function was successful.. like: $FilePath = "d:\store\dat\mitran.mdb" $BakFilePath = "d:\store\dat\mitran.bak" FileCopy ($FilePath, $BakFilePath, 1) ; Initial Copy of Mitran.bak WHILE 1 $OriFileTime = FileGetTime($FilePath) If Not @error Then ;Error checking $OriHHMMSS = ($OriFileTime[3] - 12) & ":" & $OriFileTime[4] & ":" & $OriFileTime[5] Endif $BakFileTime = FileGetTime($BakFilePath) If Not @error Then ;Error checking $BakHHMMSS = ($BakFileTime[3] - 12) & ":" & $BakFileTime[4] & ":" & $OriFileTime[5] Endif IF $BakHHMMSS <> $OriHHMMSS THEN FileCopy ($FilePath, $BakFilePath, 1) ENDIF WEND Edited January 25, 2005 by Domonoky Share this post Link to post Share on other sites
friends 0 Posted January 25, 2005 Oh.... thanks Domonoky ! I'll try it out....Hi..i think the problem is, if the FileGetTime() function has a failure, it returns numeric 1 and not an array. So if you use this as a Array, you get that error.So you have to check if the fileGetTime() function was successful.. like:$FilePath = "d:\store\dat\mitran.mdb" $BakFilePath = "d:\store\dat\mitran.bak" FileCopy ($FilePath, $BakFilePath, 1) ; Initial Copy of Mitran.bak WHILE 1 $OriFileTime = FileGetTime($FilePath) If Not @error Then ;Error checking $OriHHMMSS = ($OriFileTime[3] - 12) & ":" & $OriFileTime[4] & ":" & $OriFileTime[5] Endif $BakFileTime = FileGetTime($BakFilePath) If Not @error Then ;Error checking $BakHHMMSS = ($BakFileTime[3] - 12) & ":" & $BakFileTime[4] & ":" & $OriFileTime[5] Endif IF $BakHHMMSS <> $OriHHMMSS THEN FileCopy ($FilePath, $BakFilePath, 1) ENDIF WEND<{POST_SNAPBACK}> Share this post Link to post Share on other sites
friends 0 Posted January 31, 2005 Oh.... thanks Domonoky ! I'll try it out....<{POST_SNAPBACK}>I've tested it out... but failed, same problems !I need to know how to sync a file by using the FileGetTime()function repeatedly checking on the files.The coding shown is how I wrote it... but seems to behaving problems with the error message. I have no idea where it goes wrong....Please help me up on that... I need to settle it soon.Or, if any body has such similar script, please post thecoding and let me have a reference on it.Your help is very much appreciated. Thank you. Share this post Link to post Share on other sites
Domonoky 0 Posted January 31, 2005 (edited) Hi.. okey.. this time, i tested it a little bit.. the problem was, if you change the file in the moment the script checks for the FileTime.. the function call fails.. and the error checking wasnt right.. so here is a new version.. $FilePath = "test.txt" $BakFilePath = "test.bak" FileCopy ($FilePath, $BakFilePath, 1); Initial Copy of Mitran.bak WHILE 1 sleep 100 ;sleep a bit, so cpu isnt used all the time $OriFileTime = FileGetTime($FilePath) If @error Then ;if Error ContinueLoop ;continue at beginning of the loop Endif $OriHHMMSS = ($OriFileTime[3] - 12) & ":" & $OriFileTime[4] & ":" & $OriFileTime[5] $BakFileTime = FileGetTime($BakFilePath) If @error Then ;Error checking ContinueLoop Endif $BakHHMMSS = ($BakFileTime[3] - 12) & ":" & $BakFileTime[4] & ":" & $OriFileTime[5] IF $BakHHMMSS <> $OriHHMMSS THEN FileCopy ($FilePath, $BakFilePath, 1) ENDIF WEND I think this should work.. if not, look in the help file an make more error checking.. mfg Domonoky Edited January 31, 2005 by Domonoky Share this post Link to post Share on other sites
friends 0 Posted February 4, 2005 Hi domonokiy, I'll test the *new* coding again.... thanks for the feedback !Hi..okey.. this time, i tested it a little bit.. the problem was, if you change the file in the moment the script checks for the FileTime.. the function call fails.. and the error checking wasnt right..so here is a new version..$FilePath = "test.txt" $BakFilePath = "test.bak" FileCopy ($FilePath, $BakFilePath, 1); Initial Copy of Mitran.bak WHILE 1 sleep 100 ;sleep a bit, so cpu isnt used all the time $OriFileTime = FileGetTime($FilePath) If @error Then ;if Error ContinueLoop ;continue at beginning of the loop Endif $OriHHMMSS = ($OriFileTime[3] - 12) & ":" & $OriFileTime[4] & ":" & $OriFileTime[5] $BakFileTime = FileGetTime($BakFilePath) If @error Then ;Error checking ContinueLoop Endif $BakHHMMSS = ($BakFileTime[3] - 12) & ":" & $BakFileTime[4] & ":" & $OriFileTime[5] IF $BakHHMMSS <> $OriHHMMSS THEN FileCopy ($FilePath, $BakFilePath, 1) ENDIF WENDI think this should work.. if not, look in the help file an make more error checking..mfg Domonoky<{POST_SNAPBACK}> Share this post Link to post Share on other sites