Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Copying/Moving files only after full write.

Posted on 1999-06-24
7
Medium Priority
?
141 Views
Last Modified: 2010-05-02
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.  
0
Comment
Question by:tryinhard
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 12

Expert Comment

by:mark2150
ID: 1519607
have your loop try to RENAME the file. It'll fail with an ERROR until the file is completed being written.

M

0
 

Author Comment

by:tryinhard
ID: 1519608
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.
0
 

Expert Comment

by:gshriki
ID: 1519609
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.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 2

Accepted Solution

by:
s_lavie earned 200 total points
ID: 1519610
I guess mark2150 had a point.
Use a function that checks if a file is copied:

Private Function isFileExists(fullPath as string) as Boolean

isFileExists = False

On Error Resume Next
Open fullPath for input as #1
If Err.Number = 53 then Exit Function ' file not found
Close #1

isFileExists = True

End Function

Now call to isFileExists within a loop until it is True.
0
 
LVL 12

Expert Comment

by:mark2150
ID: 1519611
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

0
 

Author Comment

by:tryinhard
ID: 1519612
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!!


0
 
LVL 12

Expert Comment

by:mark2150
ID: 1519613
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

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question