Jump to content
Sign in to follow this  
friends

FileGetTime Error...

Recommended Posts

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

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 by Domonoky

Share this post


Link to post
Share on other sites

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

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 be

having 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 the

coding 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

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 by Domonoky

Share this post


Link to post
Share on other sites

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     
WEND

I 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

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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...