VBscript to confirm list of files exist and have been modified same day -
i trying create script scan directory list of specific file names , check whether or not datelastmodified newer prior day.
if of files not exist or exist not 'fresh' summary window pop @ end listing file names did not meet criteria.
as example can path c:\testing\ , files want scan file1.txt, file2.txt , file3.txt
note: although these files have same extension not want scan them way. want identify files in script since there other txt files located in directory.
update:here able create far handling 1 file @ time. can offer appreciated.
option explicit dim fso set fso = createobject("scripting.filesystemobject") dim inputfile1 inputfile1 = ("c:\testing\file1.txt") dim inputfile2 inputfile2 = ("c:\testing\file2.txt") dim inputfile3 inputfile3 = ("c:\testing\file3.txt") dim currentdate, olddate '* default date format mm/dd/yyyy currentdate = date() olddate = date() - 1 wscript.echo ("the current date on system set " & currentdate) & vbcrlf & ("checking if file newer " & olddate) if fso.fileexists(inputfile1) if cdate (fso.getfile(inputfile1).datelastmodified) > olddate wscript.echo ("all good!") else wscript.echo ("file not current.") end if else wscript.echo ("file not exist.") wscript.quit end if
and if add logfile of course try :
option explicit dim ws,fso,files,file,olddate,logfile set ws = createobject("wscript.shell") set fso = createobject("scripting.filesystemobject") files = array("c:\testing\file1.txt", "c:\testing\file2.txt", "c:\testing\file3.txt") olddate = date() - 1 wscript.echo "checking if files older " & olddate logfile = left(wscript.scriptfullname, instrrev(wscript.scriptfullname, ".")) & "log" if fso.fileexists(logfile) fso.deletefile logfile end if each file in files if fso.fileexists(file) if fso.getfile(file).datelastmodified < olddate wscript.echo "not current: " & dblquote(file) writelog "not current: " & dblquote(file),logfile end if else wscript.echo "not found: " & dblquote(file) writelog "not found: " & dblquote(file),logfile end if next if fso.fileexists(logfile) ws.run dblquote(logfile) end if '********************************************************** sub writelog(strtext,logfile) dim fs,ts const forappending = 8 set fs = createobject("scripting.filesystemobject") set ts = fs.opentextfile(logfile,forappending,true) ts.writeline strtext ts.close end sub '*********************************************************** function dblquote(str) dblquote = chr(34) & str & chr(34) end function '***********************************************************
edit : 26/04/2015 ==> here how set rootfolder variable
option explicit dim ws,fso,files,file,olddate,logfile,rootfolder set ws = createobject("wscript.shell") set fso = createobject("scripting.filesystemobject") rootfolder = "c:\testing" set rootfolder = fso.getfolder(rootfolder) olddate = date() - 1 wscript.echo "checking if files older " & olddate logfile = left(wscript.scriptfullname, instrrev(wscript.scriptfullname, ".")) & "log" if fso.fileexists(logfile) fso.deletefile logfile end if each file in rootfolder.files if fso.fileexists(file) if fso.getfile(file).datelastmodified < olddate wscript.echo "not current: " & dblquote(file) writelog "not current: " & dblquote(file),logfile end if else wscript.echo "not found: " & dblquote(file) writelog "not found: " & dblquote(file),logfile end if next if fso.fileexists(logfile) ws.run dblquote(logfile) end if '********************************************************** sub writelog(strtext,logfile) dim fs,ts const forappending = 8 set fs = createobject("scripting.filesystemobject") set ts = fs.opentextfile(logfile,forappending,true) ts.writeline strtext ts.close end sub '*********************************************************** function dblquote(str) dblquote = chr(34) & str & chr(34) end function '***********************************************************
Comments
Post a Comment