here is a little program I wrote a while back it checks every few seconds minutes hours whatever if a file is up to date or not and if it isn't it will update it. It has some simple error handling and a basic settings file that is will create and read from when it is ran. designed it to back up files I was working on. can run it in hidden mode as well in the background.
Rem Project: Server Backup
Rem Created: 6/5/2011 1:44:34 PM
Rem Version: 1.0 b
`If settings file does not exist create.
If file exist("settings.ini")=0
open to write 2,"settings.ini"
write string 2,"Window:=True"
write string 2,"Time:=600"
write string 2,"DIR:=C:\"
write string 2,"Name:=Test.txt"
close file 2
endif
`read settings file store variables for program use
if file exist("settings.ini")=1
if file open (3)=1
close file 3
endif
open to read 3,"settings.ini"
read string 3,window$
read string 3,time$
read string 3,dir$
read string 3,name$
close file 3
pdir=len(dir$)-5
ndir$=right$(dir$,pdir)
pname=len(name$)-6
nname$=right$(name$,pname)
pwindow=len(window$)-8
nwindow$=right$(window$,pwindow)
ptime=len(time$)-6
ntime$=right$(time$,ptime)
endif
set dir ndir$
`Hidden mode as service
if nwindow$="false"
hide window
gosub subroutine
endif
do
`logic check. Check window show value
check:
open to read 3,"settings.ini"
read string 3,window$
pwindow=len(window$)-8
nwindow$=right$(window$,pwindow)
close file 3
if nwindow$="false"
hide window
return
else
restore window
endif
`end check
if file exist(nname$) =1
if file open(1)=1
close file 1
endif
open to read 1,nname$
read string 1,date$
if date$=get date$()
print "File Is Up To Date Esc to exit."
else
print "WARNNING: Backup File Is outdated."
print "Last Backup Was On Date: "+date$
print "Would you like to update it?"
print "Type [Y] For Yes"
print "Type [N] For No"
input a$
if a$="y"
cls
if file open(1)=1
close file 1
endif
delete file nname$
open to write 1,nname$
write string 1,get date$()
print "File Has Been Updated."
endif
endif
if a$="n"
cls
print "File Has Not Been Updated. Exiting....."
wait 3000
end
endif
else
print "WARNNING: Server Backup File"
print "Does not exist"
Print "Create File?"
print "Type [Y] To Create"
input b$
if b$="y"
open to write 1,nname$
write string 1,get date$()
close file 1
Print "File Has Been Created and Updated."
endif
endif
wait val(ntime$)*1000
loop
subroutine:
open to read 3,"settings.ini"
read string 3,window$
pwindow=len(window$)-8
nwindow$=right$(window$,pwindow)
close file 3
if file exist(nname$) =0
open to write 1,nname$
close file 1
endif
if file open(1)=1
close file 1
endif
open to read 1,nname$
read string 1,date$
if date$=get date$()
close file 1
wait val(ntime$)*1000
gosub check
goto subroutine:
`end of repeat
else
if file open(1)=1
close file 1
endif
delete file nname$
open to write 1,nname$
write string 1,get date$()
close file 1
`logic check for write protection
open to read 1,nname$
read string 1,date$
if date$=get date$()
goto subroutine:
else
`If program fails to write to file.
print "warning Cannot write to file"
print ndir$+nname$
print "This program does not have proper promission"
print "or is dedicated to another resource."
print "Please contact the software developer"
wait 6000
cls
print "This Program will terminate please"
print "Check the file and restart the program."
print "Press any key to close."
lock backbuffer
wait key
end
endif
endif
A child's dream never dies.