detect file status

  • Thread starter Thread starter Tony WONG
  • Start date Start date
T

Tony WONG

my 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
 
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.
 
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.
 
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).
 
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 said:
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.


Armin
 
Andreas said:
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.


Armin
 
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

--
 
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

--
 
Armin said:
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.

Andreas, this was no disagreement (it could be read as if). Just an
addition.


Armin
 
Armin said:
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.

Andreas, this was no disagreement (it could be read as if). Just an
addition.


Armin
 
Back
Top