LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Move Function Fails with Error 5: File already open.

This piece of code fails intermittently on the 2nd iteration.  Never fails when stepping through.

paul_a_cardinale_0-1719000896512.png The sources files are different; but the destination is always the same, a folder.

I guessed that due to lazy writes by the OS, the 2nd iteration fails because the destination folder is being held open until the write from the 1st iteration finishes.

So I tried this:

paul_a_cardinale_2-1719001064939.png

Slows it down, but doesn't fix the problem.

Any suggestions?

Message 1 of 13
(13,465 Views)

That is weird, how large are the files? LV version and Windows?

BTW, I like your retry implementation, learnt a new technique, thanks!

Santhosh
Soliton Technologies

New to the forum? Please read community guidelines and how to ask smart questions

Only two ways to appreciate someone who spent their free time to reply/answer your question - give them Kudos or mark their reply as the answer/solution.

Finding it hard to source NI hardware? Try NI Trading Post
0 Kudos
Message 2 of 13
(13,457 Views)

I tried to solve a similar problem (not error 5, intermittent error 8 on a network drive) and I tried using .NET file moves instead.  It seemed to work better, maybe give that a go?

 

Kyle97330_0-1719003265208.png

 

0 Kudos
Message 3 of 13
(13,442 Views)

@santo_13 wrote:

That is weird, how large are the files? LV version and Windows?

BTW, I like your retry implementation, learnt a new technique, thanks!


LV 2019

Win 10 pro

1st file is 823 KB

2nd file is 25 KB

0 Kudos
Message 4 of 13
(13,428 Views)

@paul_a_cardinale wrote:

This piece of code fails intermittently on the 2nd iteration.  Never fails when stepping through.

paul_a_cardinale_0-1719000896512.png The sources files are different; but the destination is always the same, a folder.

I guessed that due to lazy writes by the OS, the 2nd iteration fails because the destination folder is being held open until the write from the 1st iteration finishes.

So I tried this:

paul_a_cardinale_2-1719001064939.png

Slows it down, but doesn't fix the problem.

Any suggestions?


Did you try flushing the file buffers?

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 5 of 13
(13,385 Views)

@billko wrote:


Did you try flushing the file buffers?


The flush function takes a file refnum; but the Move function doesn't give one.  So I tried Open, Flush, Close; but that didn't help.

0 Kudos
Message 6 of 13
(13,368 Views)

I tried replacing the Move function with Copy followed by Delete.  It's the Delete that throws the error.

 

The VI that's running this code is a post-build action that runs as part of the build process.

The files that are being moved are ones that were created by the build.  Maybe the app builder hasn't finished closing them when it calls the post-build VI.

But then why does my retry loop never succeed?

0 Kudos
Message 7 of 13
(13,364 Views)

Maybe the App Builder maintains an open reference to your file until the end of the post-build action? If you disable the post-build, do the build, then manually execute the post-build (with the appropriate inputs), does the file get deleted? If yes, that means the App Builder may have a bug...

 

The App Builder pre/post-build actions are not "strict" pre/post-build actions in the sense that something is done before the pre-build (like loading the build spec properties and the source files to build) and something is done after the post-build (like apparently closing some files and removing everything in case of fail).

 

This is one of the reasons why, for complex applications, I have resorted to coding my own builder VI using the App Builder API. My builder VI can then be called e.g. from a batch file and integrated in a higher-level compilation process.

 

With a custom builder VI, you can perform true pre/post-build operations like, before the build, modifying the build spec properties or doing some scripting on the VIs without interfering with what the App Builder loads into memory.

 

Regards,

Raphaël.

0 Kudos
Message 8 of 13
(13,356 Views)

@paul_a_cardinale wrote:

The VI that's running this code is a post-build action that runs as part of the build process.

The files that are being moved are ones that were created by the build.  Maybe the app builder hasn't finished closing them when it calls the post-build VI.


OK, that seems to be important information! Up until now I had no clue what you are trying to do and what are folders and what are files. 😄

 

I don't use pre/post build actions but do my own script that builds a source distro, an application, and an installer in sequence and at the very end moves everything to a new destination folder while renaming things. Besides the full automation (as project menu entry "build all") it also prevents problems because the build should happen in a folder that is not linked to the cloud (google drive, OneDrive, etc), while the final location should be in a monitored folder. See also this idea.

 

I guess one question would be if the involved hierarchy is a monitored location.

0 Kudos
Message 9 of 13
(13,336 Views)

@raphschru wrote:

Maybe the App Builder maintains an open reference to your file until the end of the post-build action?


Seems unlikely because the problem is intermittent.

0 Kudos
Message 10 of 13
(13,310 Views)