Solved

VBScript -  Ignore any source files with today's date

Posted on 2012-04-03
6
456 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
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 
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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

How to update Firmware and Bios in Dell Equalogic PS6000 Arrays and Hard Disks firmware update.
The article will include the best Data Recovery Tools along with their Features, Capabilities, and their Download Links. Hope you’ll enjoy it and will choose the one as required by you.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

813 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

14 Experts available now in Live!

Get 1:1 Help Now