Dear,We have restyle your program. First some remarks:
- we try to use no goto statements. positive for readability.
- we are using DIM statement to create local variables.
- we create an array with filenames and a WHILE..LOOP structure.
- your end message "All your files are up to date...!" doesn't
mean, that the files were updated correctly. we introduce a $errors
variable.
- we add the /H to your copy command.
- we eliminate variables which are used only once.
Our idea:
code:
; **************************************************************************
; ** GIS Updates
; **************************************************************************
CLS
BREAK OFF
IF (Exist("C:\Jdaodbms\Project") = 1)
GOSUB main_update_files
ENDIF
RETURN ; - exit script -
:main_update_files
DIM $location, $serverpath, $imagefile, $backupdir
$location="C:\Jdaodbms\Project"
$serverpath="@LSERVER\NETLOGON\UPDATES\GIS"
$imagefile="C:\Jdaodbms\Images"
$backupdir="$location\Backup"
IF (Exist("$backupdir") = 0)
MD "$backupdir"
ENDIF
DIM $number_of_files
$number_of_files=14
DIM $errors
$errors=0
; **************************************************************************
; ** Destination locations
; **************************************************************************
DIM $source_file[$number_of_files+1]
$source_file[ 1]="$location\buyu0194.frm"
$source_file[ 2]="$location\finq0008.frm"
$source_file[ 3]="$location\basu0060.frm"
$source_file[ 4]="$location\basu0062.frm"
$source_file[ 5]="$location\basu0201.frm"
$source_file[ 6]="$location\blk_m0001.frm"
$source_file[ 7]="$location\blk_q0001.frm"
$source_file[ 8]="$location\blk_q0002.frm"
$source_file[ 9]="$location\blk_u0001.frm"
$source_file[10]="$location\blk_u0002.frm"
$source_file[11]="$location\blk_u0003.frm"
$source_file[12]="$location\bass0089.frm"
$source_file[13]="$location\capq0003.frm"
$source_file[14]="$imagefile\blokker1.bmp"
; **************************************************************************
; ** Source locations
; **************************************************************************
DIM $dest_file[$number_of_files+1]
$dest_file[ 1]="$serverpath\buyu0194.frm"
$dest_file[ 2]="$serverpath\finq0008.frm"
$dest_file[ 3]="$serverpath\basu0060.frm"
$dest_file[ 4]="$serverpath\basu0062.frm"
$dest_file[ 5]="$serverpath\basu0201.frm"
$dest_file[ 6]="$serverpath\blk_m0001.frm"
$dest_file[ 7]="$serverpath\blk_q0001.frm"
$dest_file[ 8]="$serverpath\blk_q0002.frm"
$dest_file[ 9]="$serverpath\blk_u0001.frm"
$dest_file[10]="$serverpath\blk_u0002.frm"
$dest_file[11]="$serverpath\blk_u0003.frm"
$dest_file[12]="$serverpath\bass0089.frm"
$dest_file[13]="$serverpath\capq0003.frm"
$dest_file[14]="$serverpath\blokker1.bmp"
; **************************************************************************
DIM $i
$i=1
WHILE ($i <= $number_of_files)
GOSUB update_files
$i=$i+1
LOOP
IF ($errors = 0)
$prompt="All your files are up to date...!"
ELSE
$prompt="All your files are up to date! "+$errors+" errors found."
ENDIF
GOSUB center
SLEEP 1
$prompt=" "
GOSUB center
CLS
RETURN
; **************************************************************************
:update_files
IF (Exist($source_file[$i]) = 0)
$errors=$errors+1
$prompt="File '"+LCASE($source_file[$i])+"' not present on client."
GOSUB center
ENDIF
IF (Exist($dest_file[$i]) = 0)
$errors=$errors+1
$prompt="File '"+LCASE($dest_file[$i])+"' not present on server."
GOSUB center
ENDIF
IF (GetFileTime($source_file[$i]) <> GetFileTime($dest_file[$i])) ; $source_file[$i] not the same as $dest_file[$i]?
$prompt="Copying file... $dest_file[$i]"
GOSUB center
$prompt=" "
GOSUB center
COPY $source_file_a $backupdir /H ; - make a backup from original -
COPY $dest_file_a $location /H ; - copy the new file -
ENDIF
RETURN
; **************************************************************************
:center
COLOR n/n
Box (22,1,24,78,double) ; erase the bar
COLOR w/n
At (23,40-(Len($prompt)/2)) $prompt
SLEEP 1
RETURN
; **************************************************************************
Greetings.