Jump to content

Recommended Posts

Posted

Hello,

Happy New Year to everyone.

Can someone help me with a script please?

I have a Windows XP Pro box that has files dumped to it all day every day. What I need the script to do is:

1. Search a specific directory for NEW files

2. Copy them to another directory.

I need files that were created at 9AM, then when the script runs again, I need it to find files that were created after 9AM, then after the last run and so forth ... In UNIX I can do this with the "-newer" command, but I don't know how to accomplish this on Windows.

A VB script would be great!


Posted

One idea I have is to use the scheduler to create a new marker file then run a script then delete the marker. I don't know if a file being part copied at the wrong time could create a problem, so I'd need verification of exactly what your requirements are, files created after or files modified after for instance.

Until I know more the best I can do is suggest you familiarize yourself with robocopy.

Posted
One idea I have is to use the scheduler to create a new marker file then run a script then delete the marker. I don't know if a file being part copied at the wrong time could create a problem, so I'd need verification of exactly what your requirements are, files created after or files modified after for instance.

Until I know more the best I can do is suggest you familiarize yourself with robocopy.

In UNIX I created a file. Had a script look for files that are newer than the file I created and then "touch" my file. When the script ran again, it would look for files that have been created since the last "touch".

I have Robocopy. But I don't see where it can get files that are created within the time the script ran last.

Posted

Here is a VBS script that will do what you want.

You will have to change these to entries to match

the folders you want to use

 Change This Location To Match Your Needs
StrFolder = "C:\TestFolder"
StrTarget = "C:\CopyFolder"

Save As FileTimeCheck.vbs

Option Explicit
Dim ColFiles, IntTime, ObjFile
Dim StrComputer, strCurrentDate, strFileDate, StrFolder, StrTarget
'-> Set The Computer To Local
StrComputer = "."
'-> Folder You Want To Check Path
StrFolder = "C:\TestFolder"
'/-> Folder To Copy To
StrTarget = "C:\CopyFolder"
'->
Dim Wmi :Set Wmi = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
'/->
Set ColFiles = Wmi.ExecQuery _
("ASSOCIATORS OF {Win32_Directory.Name='" & StrFolder & "'} Where " _
& "ResultClass = CIM_DataFile")
'-> Set Time
strCurrentDate = Now
'-> Collect The Files In The Target Folder
For Each ObjFile In ColFiles
strFileDate = WMIDateStringToDate(ObjFile.CreationDate)
'-> Check Time In Hours, Uncomment To Use
'IntTime = DateDiff("h", strFileDate, strCurrentDate)
'-> Check Time In Minutes, Uncomment To Use
IntTime = DateDiff("n", strFileDate, strCurrentDate)
'-> Check Amount Of IntTime
If IntTime >= 5 Then
ObjFile.Copy(StrTarget)
End If
Next
'-> Convert The WMI Time
Function WMIDateStringToDate(dtmInstallDate)
WMIDateStringToDate = CDate(Mid(dtmInstallDate, 5, 2) & "/" & _
Mid(dtmInstallDate, 7, 2) & "/" & Left(dtmInstallDate, 4) _
& " " & Mid (dtmInstallDate, 9, 2) & ":" & _
Mid(dtmInstallDate, 11, 2) & ":" & Mid(dtmInstallDate, 13, 2))
End Function

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...