Hi there..
I have a very limited knowledge of VBScript, and need to code a script (to be used as an ActiveX script in SQL) and could do with some pointers please..
The script that I need to write will need to do the following points:
1: Check a network share for a CSV that has a datestamp on it (FilenameDDMMYY.csv).
2: If this file's DDMMYY section is within 7 days of the date running the script.
3: Copy the file to \\server\share\CurrentImport.csv (overwriting existing file)
I know that this is next to nothing, so sorry about that, but I am having problems with extracting the DDMMYY section of the original filename, and check that against the current date.
I think I need to add something like:
any help is gratefully recieved.. thanks
I have a very limited knowledge of VBScript, and need to code a script (to be used as an ActiveX script in SQL) and could do with some pointers please..
The script that I need to write will need to do the following points:
1: Check a network share for a CSV that has a datestamp on it (FilenameDDMMYY.csv).
2: If this file's DDMMYY section is within 7 days of the date running the script.
3: Copy the file to \\server\share\CurrentImport.csv (overwriting existing file)
Code:
Const OverwriteExisting = True
Dim objPath
Dim objFile
Dim odjDstFile
set objFSO = CreateObject("Scripting.FileSystemObject")
'Sets UNC path
set objPath = objFSO.GetFolder("\\server\share")
'wscript.echo objSrcPath
'Sets Source file name
set objFile = objFSO.GetFile (objPath & "\FilenameDDMMYY.csv")
'wscript.echo objfile
'Sets Destination File
set objDstFile = objFSO.GetFile (objPath & "\CurrentImport.csv")
I know that this is next to nothing, so sorry about that, but I am having problems with extracting the DDMMYY section of the original filename, and check that against the current date.
I think I need to add something like:
Code:
Dim DtStamp, Dt2Day
set DtStamp = substring(objFile 23, 4) 'should give DDMMYY? i am not sure about this and without a debugger is quite hard to tell.. the 23 indicates the 23rd character of the objFile string is the start of the DtStamp string, and that it continues for 4 characters
set Dt2Day = date
If DtStamp = (Dt2Day - 7) Then
objFSO.CopyFile objFile, objDstFile, OverwriteExisting
else
wscript.echo "File is still current"
end if
any help is gratefully recieved.. thanks