Sign in to follow this  
Followers 0
egridley

Watchfolder Script

7 posts in this topic

I am trying to create a script that will watch a folder and when files show up it runs some commands against those files. Other computers are copying files into this folder. However, the files are very large and take a while to copy. So I need to make sure the files are finished copying before I start processing them.

I have searched but haven't been able to find some sample code that can accomplish this. Does anyone know if this is available somewhere or how to accomplish this?

Share this post


Link to post
Share on other sites



Hi,

search for "FileInUse".

HTH, Reinhard

Share this post


Link to post
Share on other sites

egridley,

I have used FileSystemMonitor from seangriffin to do this successfully. :mellow:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

egridley,

I have used FileSystemMonitor from seangriffin to do this successfully. :mellow:

M23

I've used this one, too, but couldn't manage to find it in the forum so quickly. :)

Anyway, does it report files that are still in copy progress?


Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler]

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

hannes08,

does it report files that are still in copy progress?

I seem to remember that it only announces that files have been added once they are closed post copying/creation. But as the OP is only interested in the files from that point on, it should do the trick. :mellow:

M23

Edit: I was wrong - see below for a workaround. :)

Edited by Melba23

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

This function seems to report that files have been added once the copy starts. As a side note, I am copying files from a network location. Would that have anything to do with it?

Share this post


Link to post
Share on other sites

egridley,

Looking back to when I used this UDF, I see that my earlier comment was incorrect - sorry.

I used the following code to detect when the file copying was complete:

; Initial declarations
Global $sFileName = "", $iFileSize = 0, $iCurrSize, $iBegin = 0
Global $fSizeCheck = False, $fRewrite = False
; Loop
While 1
; Handle Directory related events
_FileSysMonDirEventHandler()
Sleep(100)
; Check new file size to see if writing ended
If $fSizeCheck Then
  $iCurrSize = FileGetSize($sFolder & "\" & $sFileName)
  If $iCurrSize <> $iFileSize Then
   ; Still being written
   $iFileSize = $iCurrSize
  Else
   ; Closed so insert S values
   $fRewrite = True
   ; Do what you need here <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
   $fSizeCheck = False
  EndIf
EndIf
WEnd
Func _FileSysMonActionEvent($iEvent_Type, $iEvent_ID, $sEvent_FileName)
#forceref $iEvent_Type
; Prevent double insertion into rewritten file
If $fRewrite Then Return
; Check name is one we are looking for
If Not StringInStr($sEvent_FileName, "-OP.src") Then Return
Switch $iEvent_ID
  Case 1
   ; The file has just appeared
   $sFileName = $sEvent_FileName
   ; And this is its size
   $iFileSize = FileGetSize($sFolder & "\" & $sEvent_FileName)
  Case 3
   ; The file is being modified
   $fSizeCheck = True
   If $fRewrite Then $fSizeCheck = False
EndSwitch
EndFunc

I hope that is useable after the forum upgrade and understandable as code.

Please ask if not! :mellow:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

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
Sign in to follow this  
Followers 0