egridley Posted August 29, 2011 Share Posted August 29, 2011 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? Link to comment Share on other sites More sharing options...
ReFran Posted August 29, 2011 Share Posted August 29, 2011 Hi, search for "FileInUse". HTH, Reinhard Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted August 29, 2011 Moderators Share Posted August 29, 2011 egridley, I have used FileSystemMonitor from seangriffin to do this successfully. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
hannes08 Posted August 29, 2011 Share Posted August 29, 2011 egridley, I have used FileSystemMonitor from seangriffin to do this successfully. 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] Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted August 29, 2011 Moderators Share Posted August 29, 2011 (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. M23 Edit: I was wrong - see below for a workaround. Edited August 29, 2011 by Melba23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
egridley Posted August 29, 2011 Author Share Posted August 29, 2011 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? Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted August 29, 2011 Moderators Share Posted August 29, 2011 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: expandcollapse popup; 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! M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now