VBSCRIPT: Ignore files created today

I am running an program that uni-directly copies from source to destination.  The following script runs in conjunction and skips any files with a "date modified" equaling the same day the program is running.

I'd like to modify the script to skip any files with a "created" date equaling today's date and allow any other files regardless of "modified" date.

Essentially, the same script, but using "Date Created" verses "Date Modified."

Thank you in advance,
________________________________________________________

Function Description(ScriptType)
  Description = "Ignores any source files 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

  ' 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 = TRUE
  Else
    Skip = FALSE
  End If
End Sub
LVL 1
CappperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

x-menIT super heroCommented:
File.GetCreationTime Method

Returns the creation date and time of the specified file or directory.

If DateDiff("d", SBRunning.GetCreationTime(Filename), Date) = 0 Then


in:http://msdn.microsoft.com/en-us/library/system.io.file.getcreationtime(v=vs.110).aspx?cs-save-lang=1&cs-lang=vb#code-snippet-2
0
CappperAuthor Commented:
No Dice.  It's still copying files with a creation date equaling today.
_________________________________________________
Function Description(ScriptType)
  Description = "Ignores any source files created 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

  ' See if the file date is the same as todays date, skip if so
  If DateDiff("d", SBRunning.GetCreationTime(Filename), Date) = 0 Then
    Skip = TRUE
  Else
    Skip = FALSE
  End If
End Sub
_________________________________________________
0
RobSampsonCommented:
Hi, it would help to know which system you are running this script in, since it appears to be a custom or emulated set of functions.  What type object is SBRunning?
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

CappperAuthor Commented:
Sorry.  Let me see if I can explain better.  There is a program called SyncBackPro.  Its a GUI file synchronization application.  You create profiles that determine source and destination paths to copy or synchronize folders and files.  You can use scripts, in conjunction with the what the program is calling, to extend the functionality beyond the scope of what the application can do.  (see attached)

The script outlined above is what is currently being used and works perfectly for skipping files with today's modified date.  However, I now need it to allow files with a modified date = today and skip files with created date = today.
script.jpg
0
RobSampsonCommented:
OK, that makes more sense now.  So on the 2brightsparks.com site, in a few threads, they state that the file creation date is not directly supported by their scripting emulation.

You can, however, use a runtime script to make use of the FileSystemObject of VBScript.
http://www.2brightsparks.com/bb/viewtopic.php?t=6423

So, I think you should be able to get away with something like this
Function Description(ScriptType)
   Description = "Ignores any source files created 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

   ' See if the file date is the same as todays date, skip if so
   'If DateDiff("d", SBRunning.GetCreationTime(Filename), Date) = 0 Then
   '  Skip = TRUE
   'Else
   '  Skip = FALSE
   'End If
   
   ' Use the FileSystemObject runtime object to check the file creation Date
	Set objFSO = CreateObject("Scripting.FileSystemObject")
	If DateDiff("d", objFSO.GetFile(Filename).DateCreated, Date) = 0 Then
		Skip = True
	Else
		Skip = False
	End If
 End Sub

Open in new window


Regards,

Rob.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CappperAuthor Commented:
Rob,
Thank you for your research and diligence.  The script above is still skipping all files modified with today's date.  I need to allow files modified today, but skip any created today.

I ran a test with 4 files
File Name    Date Created                 Date Modified
File1             8/15/2014 12:43 AM       8/15/2014 02:03 AM
File2             8/15/2014 12:41 AM       8/15/2014 01:09 AM
File3             8/14/2014 12:41 AM       8/15/2014 12:41 AM
File4             8/14/2014 12:38 AM       8/14/2014 11:32 PM

The script only copied File4 and skipped the other three.
I need it to copy File3 and File4 and Skip File1 and File2.
0
RobSampsonCommented:
Sorry for my delay.  I think we may need to see some date output so we know what we're dealing with.  When I get back tomorrow, I'll modify the script to write some output to a file, and we can review it.

Rob.
0
RobSampsonCommented:
OK, this should create a log file in the same location as the script itself, that should show you the dates of the files it is seeing.

Run this, then have a look in the log file.

Regards,

Rob.

Function Description(ScriptType)
   Description = "Ignores any source files created 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

   ' See if the file date is the same as todays date, skip if so
   'If DateDiff("d", SBRunning.GetCreationTime(Filename), Date) = 0 Then
   '  Skip = TRUE
   'Else
   '  Skip = FALSE
   'End If
   
   ' Use the FileSystemObject runtime object to check the file creation Date
	Set objFSO = CreateObject("Scripting.FileSystemObject")
	Set objLog = objFSO.OpenTextFile(Replace(WScript.ScriptFullName, WScript.ScriptName, "") & "ScriptLog.txt", 8, True)
	objLog.WriteLine Now & ": Date from script: " & Date & " - " & Filename & " has created date of " & objFSO.GetFile(Filename).DateCreated & " - DateDiff returns " & DateDiff("d", objFSO.GetFile(Filename).DateCreated, Date) & " days difference"
	If DateDiff("d", objFSO.GetFile(Filename).DateCreated, Date) = 0 Then
		objLog.WriteLine "Skipping " & Filename
		Skip = True
	Else
		objLog.WriteLine "Copying " & Filename
		Skip = False
	End If
	objLog.Close
 End Sub

Open in new window

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.