Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


detecting uploads finished

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,36408
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> detecting uploads finished
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 detecting uploads finished - 7/21/2006 3:03:45 AM   
  ziminski

 

Posts: 79
Score: 2
Joined: 1/8/2006
Status: offline
I have a script that will monitor a directory and act on any new file created. The problem is it's an ftp directory and if the file is big, the script tries to process the file before the upload is complete. I figure I need to use case "__InstanceModificationEvent" and check i't size untill it stop growing. I just don't know how; Any help would be appreciated.
code block

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colMonitoredEvents = objWMIService.ExecNotificationQuery _
   ("SELECT * FROM __InstanceOperationEvent WITHIN 2 WHERE " _
       & "Targetinstance ISA 'CIM_DirectoryContainsFile' and " _
           & "TargetInstance.GroupComponent= " _
               & "'Win32_Directory.Name=""D:\\\\FTPRoot\\\\FTP\\\\jpmcSSLClient""'")

Do While TRUE
   Set objEventObject = colMonitoredEvents.NextEvent()
  
   Select Case objEventObject.Path_.Class
  
       Case "__InstanceCreationEvent"
       Set objFSO = CreateObject("Scripting.FileSystemObject")
       strReturned = objEventObject.TargetInstance.PartComponent
strFilePath = Split(strReturned, "CIM_DataFile.Name=")(1)
strFilePath = Replace(strFilePath, """", "")
strFilePath = Replace(strFilePath, "\\", "\")
Set objFile = objFSO.GetFile(strFilePath)
objLogFile.WriteLine(strFilePath)
 objLogFile.WriteLine( "A new file was just created: " & _
 objEventObject.TargetInstance.PartComponent )
objLogFile.WriteLine("A new file was just created: " & objFile.Name)
strFile = objFile.Name
Call Main()
Case "__InstanceDeletionEvent"
               objLogFile.WriteLine " File deleted " &  Now
        End Select
Loop
Sub Main ()
/code block
 
 
Post #: 1
 
 RE: detecting uploads finished - 7/21/2006 5:05:04 AM   
  ziminski

 

Posts: 79
Score: 2
Joined: 1/8/2006
Status: offline
I have changed my code and now I have 2 questions.
11. how do I insert a vairable in  & "TargetInstance.Name='D:\\FTPRoot\\FTP\\jpmcSSLClient\\test.txt'") for the file everything I try reults in unparable query.
2.my if statement will never work, so how do you find when the file is max size?
If objLatestEvent.TargetInstance.FileSize = objLatestEvent.PreviousInstance.FileSize Then




strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colMonitoredEvents = objWMIService.ExecNotificationQuery _
   ("SELECT * FROM __InstanceOperationEvent WITHIN 2 WHERE " _
       & "Targetinstance ISA 'CIM_DirectoryContainsFile' and " _
           & "TargetInstance.GroupComponent= " _
               & "'Win32_Directory.Name=""D:\\\\FTPRoot\\\\FTP\\\\jpmcSSLClient""'")

Do While TRUE
   Set objEventObject = colMonitoredEvents.NextEvent()
  
   Select Case objEventObject.Path_.Class
  
       Case "__InstanceCreationEvent"
       Set objFSO = CreateObject("Scripting.FileSystemObject")
       strReturned = objEventObject.TargetInstance.PartComponent
strFilePath = Split(strReturned, "CIM_DataFile.Name=")(1)
strFilePath = Replace(strFilePath, """", "")
strFilePath = Replace(strFilePath, "\\", "\")
Set objFile = objFSO.GetFile(strFilePath)
objLogFile.WriteLine(strFilePath)
 objLogFile.WriteLine( "A new file was just created: " & _
 objEventObject.TargetInstance.PartComponent )
objLogFile.WriteLine("A new file was just created: " & objFile.Name)
strFile = objFile.Name
Call Mon()
Case "__InstanceDeletionEvent"
               objLogFile.WriteLine " File deleted " &  Now
        End Select
Loop
Sub mon ()
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
   & "{impersonationLevel=impersonate}!\\" & _
       strComputer & "\root\cimv2")
Set colMonitoredEvents = objWMIService.ExecNotificationQuery _
   ("SELECT * FROM __InstanceModificationEvent WITHIN 2 WHERE " _
       & "TargetInstance ISA 'CIM_DataFile' and " _
           & "TargetInstance.Name='D:\\FTPRoot\\FTP\\jpmcSSLClient\\test.txt'")
Do
   Set objLatestEvent = colMonitoredEvents.NextEvent
    objLogFile.WriteLine "File: " & objLatestEvent.TargetInstance.Name
    objLogFile.WriteLine "New size: " & objLatestEvent.TargetInstance.FileSize
    objLogFile.WriteLine "Old size: " & objLatestEvent.PreviousInstance.FileSize
    If objLatestEvent.TargetInstance.FileSize = objLatestEvent.PreviousInstance.FileSize Then
     Call main ()
End If
Loop
End Sub
Sub Main ()

(in reply to ziminski)
 
 
Post #: 2
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> detecting uploads finished Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts