Solved

VBScript -  Ignore any source files with today's date

Posted on 2012-04-03
6
455 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
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 
LVL 52

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 52

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

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.

Question has a verified solution.

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

Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
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.
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

932 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now