file io - Backup a while with added timestamp and delete original in a loop -
the main part of code work when manually started, not needed when used external program initiate, felt doing aio better ..
when added few lines delete file after backed , loop (marked pt1, pt2, pt3 in code), following syntax error:
line: 66 char 1 syntax error 800a03ea ms vbscript compilation error
as reference these links checked , copied from:
constantly file, when file exist, run command
http://www.devhut.net/2013/11/15/vbscript-backup-a-file-and-add-a-date-time-stamp/
'--------------------------------------start of added code pt1' '---------------------------------end of added code pt1' dim objfso dim ssourcefolder dim sdestfolder dim sdbfile dim sdatetimestamp const over_write_files = true set objfso = createobject("scripting.filesystemobject") ssourcefolder = "c:\program files\n h p" sbackupfolder = "c:\program files\n h p\archivedata" sdbfile = "n-h-p" sdbfileext = "csv" sdatetimestamp = cstr(year(now())) & _ pad(cstr(month(now())),2) & _ pad(cstr(day(now())),2) & _ pad(cstr(hour(now())),2) & _ pad(cstr(minute(now())),2) 'if backup folder doesn't exist, create it. if not objfso.folderexists(sbackupfolder) objfso.createfolder(sbackupfolder) end if 'copy file long file can found if objfso.fileexists(ssourcefolder & "\" & sdbfile & "." & sdbfileext) objfso.copyfile ssourcefolder & "\" & sdbfile & "." & sdbfileext,_ sbackupfolder & "\" & sdbfile & "_" & sdatetimestamp & "." & sdbfileext,_ over_write_files end if set objfso = nothing function pad(cstr2pad, reqstrlen) dim num2pad pad = cstr2pad if len(cstr2pad) < reqstrlen num2pad = string((reqstrlen - len(cstr2pad)), "0") pad = num2pad & cstr2pad end if '-------------------------------------------start of added code pt2' 'delete file long file can found if objfso.fileexists(ssourcefolder & "\" & sdbfile & "." & sdbfileext) objfso.deletefile ssourcefolder & "\" & sdbfile & "." & sdbfileext,_ over_write_files end if '-------------------------------------end of added code pt2' set objfso = nothing end function '--------------------------------start of added code pt3' wscript.sleep 50000 loop '------------------------------------start of added code pt3'
the problem here within loop. try declare new function within loop. i'd recommend formatting code bit more, makes easier find mistakes. notepad editor has visual brace matching (notepad2, notepad++, etc) help. here's code formatted , fixed, though didn't test actual copying, deleting.
dim objfso dim ssourcefolder, sdestfolder, sdbfile, sdatetimestamp const over_write_files = true set objfso = createobject("scripting.filesystemobject") ssourcefolder = "c:\program files\n h p" sbackupfolder = "c:\program files\n h p\archivedata" sdbfile = "n-h-p" sdbfileext = "csv" sdatetimestamp = cstr(year(now())) & _ pad(cstr(month(now())),2) & _ pad(cstr(day(now())),2) & _ pad(cstr(hour(now())),2) & _ pad(cstr(minute(now())),2) 'if backup folder doesn't exist, create it. if not objfso.folderexists(sbackupfolder) objfso.createfolder(sbackupfolder) end if 'copy file long file can found if objfso.fileexists(ssourcefolder & "\" & sdbfile & "." & sdbfileext) objfso.copyfile ssourcefolder & "\" & sdbfile & "." & sdbfileext,_ sbackupfolder & "\" & sdbfile & "_" & sdatetimestamp & "." & sdbfileext,_ over_write_files end if 'delete file long file can found if objfso.fileexists(ssourcefolder & "\" & sdbfile & "." & sdbfileext) objfso.deletefile ssourcefolder & "\" & sdbfile & "." & sdbfileext,_ over_write_files end if set objfso = nothing wscript.sleep 50000 loop function pad(cstr2pad, reqstrlen) dim num2pad pad = cstr2pad if len(cstr2pad) < reqstrlen num2pad = string((reqstrlen - len(cstr2pad)), "0") pad = num2pad & cstr2pad end if end function
Comments
Post a Comment