Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Checking DateStamped filenames?

Status
Not open for further replies.

tEkHEd

IS-IT--Management
Jan 29, 2003
261
GB
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)


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 :D
 
You probably need to rearrange DDMMYY into YYMMDD so it can be accepted as a date. I think yymmdd is OK, or else you might even insert separators.

Then

if DateDiff( "d", DtStamp, NOW) > 7 ...
 
Unless you really need to use this datestamp designation on the end of the filname you could use the "DateLastModified" file object property to check against. I have given an example below.


' Set # of days to check
xDays = 7

' Check if file is older than specified number of days
If oFile.DateLastModified <=Date()-xDays Then
oFSO.CopyFile(oFile, oDstFile, OverwriteExisting)
Else
WScript.Echo(&quot;File is still current&quot;)
End If

WScript.Quit
 
I eventually figured it out.. and used this code:

Code:
sCreateDate = objSrcFile.DateCreated
tdy = date

If CDate (sCreateDate) < CDate(tdy - 7) then
    msgbox  &quot;Source file is older than 7 days, aborting import!&quot;, vbCritical, &quot;Software Licensing&quot;
else 'rename the file, and run dts import package
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top