Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

VBScript -  Ignore any source files with today's date

Posted on 2012-04-03
6
Medium Priority
?
465 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
Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

 
LVL 59

Accepted Solution

by:
Bill Prew earned 2000 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 59

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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
Microsoft will be releasing the Windows 10 Creators Update in just a matter of weeks. Are you prepared? Follow these steps to ensure everything goes smoothly and you don't lose valuable data on your PC.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
Suggested Courses

916 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