MSFN Forum: Finding files - MSFN Forum

Jump to content



Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Finding files Rate Topic: -----

#1 User is offline   bbbngowc 

  • Member
  • PipPip
  • Group: Members
  • Posts: 127
  • Joined: 09-August 06

Posted 03 January 2008 - 08:27 AM

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!


#2 User is offline   Yzöwl 

  • Wise Owl
  • Group: Super Moderator
  • Posts: 4,117
  • Joined: 13-October 04
  • OS:Windows 7 x64

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.

#3 User is offline   bbbngowc 

  • Member
  • PipPip
  • Group: Members
  • Posts: 127
  • Joined: 09-August 06

Posted 03 January 2008 - 11:28 AM

View PostYzö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.



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 User is offline   bbbngowc 

  • Member
  • PipPip
  • Group: Members
  • Posts: 127
  • Joined: 09-August 06

Posted 03 January 2008 - 11:32 AM

Actually I see that I can use the "newer" option in ROBOCOPY as well. Thanks.

#5 User is offline   gunsmokingman 

  • MSFN Addict
  • Group: Super Moderator
  • Posts: 1,991
  • Joined: 02-August 03
  • OS:none specified
  • Country: Country Flag

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

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


Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users



All trademarks mentioned on this page are the property of their respective owners
Copyright © 2001 - 2011 msfn.org
Privacy Policy