?
Solved

VBSCRIPT: Ignore files created today

Posted on 2014-08-12
8
Medium Priority
?
114 Views
Last Modified: 2015-08-21
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
0
Comment
Question by:Cappper
  • 4
  • 3
8 Comments
 
LVL 18

Expert Comment

by:x-men
ID: 40257877
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
 
LVL 1

Author Comment

by:Cappper
ID: 40258935
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
 
LVL 65

Expert Comment

by:RobSampson
ID: 40259822
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:Cappper
ID: 40261321
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
 
LVL 65

Accepted Solution

by:
RobSampson earned 2000 total points
ID: 40262098
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
 
LVL 1

Author Comment

by:Cappper
ID: 40263883
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
 
LVL 65

Expert Comment

by:RobSampson
ID: 40267083
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
 
LVL 65

Expert Comment

by:RobSampson
ID: 40269318
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

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

Make the most of your online learning experience.
If you are a mobile app developer and especially develop hybrid mobile apps then these 4 mistakes you must avoid for hybrid app development to be the more genuine app developer.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses
Course of the Month16 days, 14 hours left to enroll

864 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