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!
Page 1 of 1
Finding files
#2
Posted 03 January 2008 - 09:16 AM
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.
Until I know more the best I can do is suggest you familiarize yourself with robocopy.
#3
Posted 03 January 2008 - 11:28 AM
Yzöwl, on Jan 3 2008, 10:16 AM, said:
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.
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.
#4
Posted 03 January 2008 - 11:32 AM
Actually I see that I can use the "newer" option in ROBOCOPY as well. Thanks.
#5
Posted 03 January 2008 - 12:06 PM
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
Save As FileTimeCheck.vbs
You will have to change these to entries to match
the folders you want to use
Quote
Change This Location To Match Your Needs StrFolder = "C:\TestFolder" StrTarget = "C:\CopyFolder"
Save As FileTimeCheck.vbs
Quote
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
- ← For loop: split string and echo every token
- Programming (C++, Delphi, VB/VBS, CMD/batch, etc.)
- A script to skip line and write to one line →
Share this topic:
Page 1 of 1



Help

Back to top









