Solved

VBScript -  Ignore any source files with today's date

Posted on 2012-04-03
6
457 Views
Last Modified: 2012-04-04
I'm not a VBScript expert and I just cant seem to get the right variable.
Below is a script that Ignores any source files not modified yesterday.
I am trying to tweak this so that Ignores any source files modified today.
So if I run the script on April 4th, 2012 it will ignore any file modified with a date of April 4th, 2012.

Any help would be great.


Function Description(ScriptType)
  Description = "Ignores any source files not modified yesterday. Not used on Restore."
  ScriptType = 2
End Function

Sub RunBeforeFileCompare(Filename, ByRef Skip)
  ' Ignore if this is a Restore
  If SBRunning.Restore then
    Exit Sub
  End If

  YesterdayDate = Date - 1
  YesterdatStr = CStr(Year(YesterdayDate)) & CStr(Month(YesterdayDate)) & CStr(Day(YesterdayDate))
 
  FileDate = SBRunning.GetFileDateTime(Filename, TRUE)
  FileStr = CStr(Year(FileDate)) & CStr(Month(FileDate)) & CStr(Day(FileDate))

  If FileStr = YesterdatStr then
    Skip = FALSE
  Else
    Skip = TRUE
  End If
End Sub
0
Comment
Question by:Cappper
  • 2
  • 2
  • 2
6 Comments
 
LVL 7

Expert Comment

by:karunamoorthy
ID: 37804176
Hi Cappper,

You can try this,


Function Description(ScriptType)
  Description = "Ignores any source files not modified today. Not used on Restore."
  ScriptType = 2
End Function

Sub RunBeforeFileCompare(Filename, ByRef Skip)
  ' Ignore if this is a Restore
  If SBRunning.Restore then
    Exit Sub
  End If

  ToDate = Date
  TodatStr = CStr(Year(ToDate)) & CStr(Month(ToDate)) & CStr(Day(ToToDate))
 
  FileDate = SBRunning.GetFileDateTime(Filename, TRUE)
  FileStr = CStr(Year(FileDate)) & CStr(Month(FileDate)) & CStr(Day(FileDate))

  If FileStr = TodatStr then
    Skip = FALSE
  Else
    Skip = TRUE
  End If
End Sub
'----------------------------------------------------
Have a nice day.
from
Karunamoorthy
0
 
LVL 7

Expert Comment

by:karunamoorthy
ID: 37804776
have you tried, post your remarks pl.
0
 
LVL 1

Author Comment

by:Cappper
ID: 37807066
No.  It did not work.  When the script is enabled only folders get copied to the destination.  No files get copied regardless of the date.  When I disable the script all files get copied.
0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
LVL 53

Accepted Solution

by:
Bill Prew earned 500 total points
ID: 37807380
Here's a slightly simpler approach that should work.
Sub RunBeforeFileCompare(Filename, ByRef Skip)
  ' Ignore if this is a Restore
  If SBRunning.Restore then
    Exit Sub
  End If

  ' Get current date
  TodayDate = Date
 
  ' Get Files date
  FileDate = SBRunning.GetFileDateTime(Filename, TRUE)

  ' Calculate number of days between the two
  DiffDays = DateDiff("d", FileDate, TodayDate)

  ' See if the file date is the same as todays date, skip if so
  If DiffDays = 0 Then
    Skip = FALSE
  Else
    Skip = TRUE
  End If
End Sub

Open in new window

Which could actually be shortened up quite a bit more to:
Sub RunBeforeFileCompare(Filename, ByRef Skip)
  ' Ignore if this is a Restore
  If SBRunning.Restore Then Exit Sub

  ' See if the file date is the same as todays date, skip if so
  If DateDiff("d", SBRunning.GetFileDateTime(Filename, TRUE), Date) = 0 Then
    Skip = FALSE
  Else
    Skip = TRUE
  End If
End Sub

Open in new window

~bp
0
 
LVL 1

Author Comment

by:Cappper
ID: 37807441
Bill,
Almost perfect.  Your script only copied files with today's date instead of ignoring them.  As soon as I reversed the True and False statements it worked perfectly.

Thank you.
0
 
LVL 53

Expert Comment

by:Bill Prew
ID: 37807458
Ah yes, I see I was reading the original wording backwards.  Glad you sorted that out and it was useful, thanks.

~bp
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

By default, Carbonite Server Backup manages your encryption key for you using Advanced Encryption Standard (AES) 128-bit encryption. If you choose to manage your private encryption key, your backups will be encrypted using AES 256-bit encryption.
Create your own, high-performance VM backup appliance by installing NAKIVO Backup & Replication directly onto a Synology NAS!
This video teaches viewers about errors in exception handling.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question