Solved

VBScript -  Ignore any source files with today's date

Posted on 2012-04-03
6
454 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 51

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 51

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Storage devices are generally used to save the data or sometime transfer the data from one computer system to another system. However, sometimes user accidentally erased their important data from the Storage devices. Users have to know how data reco…
Create your own, high-performance VM backup appliance by installing NAKIVO Backup & Replication directly onto a Synology NAS!
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

758 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

20 Experts available now in Live!

Get 1:1 Help Now