|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
detect file statusmy video program keeps writing videos to a folder
i wish to write a program to move "completed" videos to another folder how can i detect the video file completed (not locked?) Thanks a lot. tony You can use the FileSystemWatcher class.
http://msdn.microsoft.com/en-us/library/system.io.filesystemwatcher.aspx Assuming that the application writing the file has the proper read/write locks you can try to open the video file for exclusive read/write in the change event of the FileSystemWatcher and then try to open it with exclusive read/write locks. If it succeeds you know the file is complete. The filesystemwatcher will not work in this case.
It's file created event is fired when the file creation starts - not when it finishes. (A fact that's really irritating in my opinion, btw). It's a better solution to simply try to open it as Andreas also suggest. Good luck, Johnny J. Show quoteHide quote "Andreas Johansson" <afjohanssonREM***@hotmail.com> skrev i meddelandet news:%23IxwJh60JHA.4880@TK2MSFTNGP03.phx.gbl... > You can use the FileSystemWatcher class. > http://msdn.microsoft.com/en-us/library/system.io.filesystemwatcher.aspx > > Assuming that the application writing the file has the proper read/write > locks you can try to open the video file for exclusive read/write in the > change event of the FileSystemWatcher and then try to open it with > exclusive read/write locks. If it succeeds you know the file is complete. > > Johnny,
You can use FileSystemWatcher (ReadDirectoryChangesW) to detect when the file is closed. When the event comes in, you attempt to open it, which will be locked and you will get error 5 or 32. From here you have choices, either you prepare a worker thread to keep trying to open or do it within the IOCP event for the close event which will happen. That can get very complicated but that depends if there a lot of events. If the OP is just looking for one, then it will be fine. TIP: Look at the file size. When not zero, it is closed. Pseudo code: if FileSize is zero do forever open file if error 5 or 32 then sleep x milliseconds continue end if copy/move file close exit loop loop -- Show quoteHide quoteJohnny Jörgensen wrote: > The filesystemwatcher will not work in this case. > > It's file created event is fired when the file creation starts - not > when it finishes. > > (A fact that's really irritating in my opinion, btw). > > It's a better solution to simply try to open it as Andreas also suggest. > > Good luck, > Johnny J. > > > "Andreas Johansson" <afjohanssonREM***@hotmail.com> skrev i meddelandet > news:%23IxwJh60JHA.4880@TK2MSFTNGP03.phx.gbl... >> You can use the FileSystemWatcher class. >> http://msdn.microsoft.com/en-us/library/system.io.filesystemwatcher.aspx >> >> Assuming that the application writing the file has the proper >> read/write locks you can try to open the video file for exclusive >> read/write in the change event of the FileSystemWatcher and then try >> to open it with exclusive read/write locks. If it succeeds you know >> the file is complete. >> >> > The purpose to use the FileSystemWatcher would be to get some kind of event
to know when it might be possible to open it. It would work to use a timer or user interaction like clicking a button also. I prefer to work with events as it usually ends up using less resources (cpu time). Thanks a lot.
"Andreas Johansson" <afjohanssonREM***@hotmail.com> ???????:89CA7BD8-2CB4-4091-AA89-51E29B3FD***@microsoft.com...Show quoteHide quote > The purpose to use the FileSystemWatcher would be to get some kind of > event to know when it might be possible to open it. It would work to use a > timer or user interaction like clicking a button also. > > I prefer to work with events as it usually ends up using less resources > (cpu time). Andreas Johansson wrote:
> The purpose to use the FileSystemWatcher would be to get some kind of It doesn't matter which event you choose. In any case he will have to try > event to know when it might be possible to open it. It would work to > use a timer or user interaction like clicking a button also. > > I prefer to work with events as it usually ends up using less > resources (cpu time). opening the file in order to know if it's still locked. There is no other way. Armin Armin Zingler wrote:
> Andreas Johansson wrote: Andreas, this was no disagreement (it could be read as if). Just an >> The purpose to use the FileSystemWatcher would be to get some kind of >> event to know when it might be possible to open it. It would work to >> use a timer or user interaction like clicking a button also. >> >> I prefer to work with events as it usually ends up using less >> resources (cpu time). > > It doesn't matter which event you choose. In any case he will have to > try opening the file in order to know if it's still locked. There is > no other way. addition. Armin
remember a forms position on the screen
how to call Change() with System.Threading.Timer If Statement, Please Help bold selected text Math functions in VB (or even a dll somewhere) Options Saving data in a datatable Export a Graphic to Excel Spreadsheets Urgent: XP, Vista logoff application (WM_QUERYENDSESSION) List Boxes Visual Studio 2008 Power Packs |
|||||||||||||||||||||||