I have a script that looks for a certain file in a folder and opens that file. For example, if the user inputs a date, 02/08/2013, it should return that file with that date in it. For some reason, it returns any file with 282013 in it. I have it coded that way because the program that creates the files, drops off the leading zeroes. Here is the breakdown of what is happening, user inputs 02/08/2013, the script grabs 1282013 (because it has 282013 in it) The logical answer is to not take out the leading zeroes, it works like a charm like that, but the program doesnt create the files with the leading zeroes. Here is some of the code:
Dim matches(1000)
Dim match_count
Dim str_matches
Set objFSO = CreateObject("Scripting.FileSystemObject")
' Get the search date
search_date = InputBox("Please enter the date to search" & vbcrlf & "You must use the format MM/DD/YYYY" & vbcrlf & "ex. 03/04/2009")
if search_date = "" then
wscript.quit
end if
date_pieces = split(search_date, "/")
' build the filename from the date pieces
date_valid = 0
Dim month
month = date_pieces(0)
fc_month = Left(month, 1)
if fc_month = 0 then
month = Right(month, 1)
end if
Dim day
day = date_pieces(1)
fc_day = Left(day, 1)
if fc_day = 0 then
day = Right(day, 1)
end if
Dim year
year = Right(date_pieces(2), 2)
date_string = month & day & "20" & year
Set dateReg = new regexp
dateReg.Pattern = date_string & "ivr.log"
Set logfolder = objFSO.GetFolder("K:\Kronos\PHONE\Log")
Set logfiles = logfolder.Files
' iterate through each file in the log folder
' as soon as we find a match, use that file
for each logfile in logfiles
'wscript.echo "Testing " & logfile & " against " & dateReg.Pattern
if dateReg.Test(logfile) then
filename = logfile
wscript.echo "Using log file: " & logfile
exit for
end if
next
if objFSO.fileexists(filename) then
Set objFile = objFSO.OpenTextFile(filename, 1)
else
wscript.echo "Can't find log file for " & search_date
wscript.quit
end if
The rest of the program doesn't pertain to my problem. I know it is something to do with the For Loop but I can't seem to figure it out.
Dim matches(1000)
Dim match_count
Dim str_matches
Set objFSO = CreateObject("Scripting.FileSystemObject")
' Get the search date
search_date = InputBox("Please enter the date to search" & vbcrlf & "You must use the format MM/DD/YYYY" & vbcrlf & "ex. 03/04/2009")
if search_date = "" then
wscript.quit
end if
date_pieces = split(search_date, "/")
' build the filename from the date pieces
date_valid = 0
Dim month
month = date_pieces(0)
fc_month = Left(month, 1)
if fc_month = 0 then
month = Right(month, 1)
end if
Dim day
day = date_pieces(1)
fc_day = Left(day, 1)
if fc_day = 0 then
day = Right(day, 1)
end if
Dim year
year = Right(date_pieces(2), 2)
date_string = month & day & "20" & year
Set dateReg = new regexp
dateReg.Pattern = date_string & "ivr.log"
Set logfolder = objFSO.GetFolder("K:\Kronos\PHONE\Log")
Set logfiles = logfolder.Files
' iterate through each file in the log folder
' as soon as we find a match, use that file
for each logfile in logfiles
'wscript.echo "Testing " & logfile & " against " & dateReg.Pattern
if dateReg.Test(logfile) then
filename = logfile
wscript.echo "Using log file: " & logfile
exit for
end if
next
if objFSO.fileexists(filename) then
Set objFile = objFSO.OpenTextFile(filename, 1)
else
wscript.echo "Can't find log file for " & search_date
wscript.quit
end if
The rest of the program doesn't pertain to my problem. I know it is something to do with the For Loop but I can't seem to figure it out.