LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

I can't delete files programatically

Greetings all-

I have an application where I want to empty out a RAID array before I stream a mongo slug of image data to it (faster write speed for the outer disk cylinders, and all that).

I wrote the attached VI to do the job.  It deletes all files in the root, and (recursively) any directories except System Volume Information and RECYCLER.  Works great.

But when I call it from inside my main routine, the folder delete action throws Error 5, "File already open".

???  What obvious thing am I missing?

Thanks,
GN
(8.5.1 on XP SP 2)


0 Kudos
Message 1 of 7
(3,666 Views)
I would think simply placing the files into a "Data" folder and just deleting that folder would be easier than having to do what you're doing. Regardless, calling the VI from another VI would make no difference, assuming that's all that you're doing in the calling VI. The only thing I can think of is that a temp folder/file is on that drive, or you have inadverdently saved the VI to that drive. What else does this main VI do? If you really want to track down this error I would suggest placing an indicator on the VI so you can see what file/folder it's trying to delete when you get the error.

Another possibility is that you have some sort of system process running that's accessing files on that drive, and you may have just run into it when you ran the VI as part of a calling program.
0 Kudos
Message 2 of 7
(3,657 Views)
Silly question, but do you have an explorer window open with the subdirectory in question selected? Maybe it's the OS causing an error..



Now is the right time to use %^<%Y-%m-%dT%H:%M:%S%3uZ>T
If you don't hate time zones, you're not a real programmer.

"You are what you don't automate"
Inplaceness is synonymous with insidiousness

0 Kudos
Message 3 of 7
(3,651 Views)
.. or a Command window.
0 Kudos
Message 4 of 7
(3,646 Views)
You are correct, but I can't control what my users will do....  so I'm trying to make something robust.

In the actual case where I am getting the failure, all the images are in a single folder.  This folder is on the E: drive.  There is nothing else on the E: drive, certainly not my code.  (Remember, the VI works fine when I run it directly, which means that I have a very empty E: drive immediately after.)

I can delete the files after they are created using Explorer, and get no error messages about files being in use.  My main routine call FM_DeleteAll as its absolute first action, in order to avoid other problems.  I'm using a sequence structure and error wires to ensure that nothing else happens in my program until this routine completes.  (The rest of the program uses a frame grabber to stream a large number of large images to disk.  Nothing elaborate.)
0 Kudos
Message 5 of 7
(3,641 Views)
Phillip-

Not a silly question.  Alas, the answer is "no".

(By the way XP is "modern":  LabVIEW can delete a folder even if Explorer has it open.  Not so if an applicaition has one of the files open, or the directory is active in a DOS window...)
0 Kudos
Message 6 of 7
(3,637 Views)
OK, well, I solved it, although I will be the first to tell you that the solution is ugly (ugly, ugly, ugly).

1.  Use the Simple Error Handling vi from the Dialog & User Interface palette to supress the reporting of any and all errors.

2.  Call my routine FM_DeleteAll.vi twice in a row.

Don't know why it works.  Don't really care.  Movin' on....
0 Kudos
Message 7 of 7
(3,610 Views)