tryinhard
asked on
Copying/Moving files only after full write.
Hello all. Please help me with this. I need a quick solution to copying/moving files within VB 5.0 but ONLY after it has fully been written to the directory. I currently have an application that uses an infinite loop to search several directories for files and there is no problem with moving a file into them since it really just moves an OS pointer, but copying a large file does cause problem. Is there a relatively easy solution to this problem in VB 5.0, say... a function to retrieve status, then pass that to a copy function, or does it require full api writing, include wait/change notifications?
Please help.
thank you.
Please help.
thank you.
ASKER
sorry, but the point is to not get any errors......I need first to copy the file, then to move it. I really need to have access to knowledge of when the file is completely written and a method for operations then.
before the file is completly weritten, you can see it's name in the directory, but the size will be zero length. maybe you can wait until the file appears in the directory, and then wait for it's size to be larger then 0.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You set an ERROR TRAP that handles the *EXPECTED* error - the operator never sees it.
ON ERROR GOTO NOTYET
NAME Old AS New
'
' You get here when you've got file!
'
...
NOTYET:
DoEvents
RESUME 'Retry line that failed
Simple enough, no?
M
ON ERROR GOTO NOTYET
NAME Old AS New
'
' You get here when you've got file!
'
...
NOTYET:
DoEvents
RESUME 'Retry line that failed
Simple enough, no?
M
ASKER
yes, yes...that solves it. I see now what mark was saying, it just wasn't said clearly, and in this case re-naming the file is not an option, though what he meant is essentially the same idea.
s_lavie's comments were what triggered my understanding, so do accept the points and my thanks... I just learned an important technique!!
s_lavie's comments were what triggered my understanding, so do accept the points and my thanks... I just learned an important technique!!
The one advantage to the rename process is that a rename operator is 'atomic'. That is to say if two rename requests hit the server at once, only one will be honored. It'll either work 100% or fail, no half measures. If you're in a situation where you have *several* machines running on a net and you want to make sure that one and only one processes the file, then renaming to a unique name (perhaps a randomly generated one) allows you to *verify* that you got the file. If the target file name is present, then *YOUR* thread and *NO OTHER* has the file. This also has the advantage of working independent of the OS of the computer or the LAN. You can have a mix of DOS/Win 3.1/Win 95/NT stations running on NT/Novell/Banyon Vines, etc. LAN and it will *STILL* work correctly.
M
M
M