[WD19] How to close and delete a stubborn text file?

Startbeitrag von Ola am 25.07.2015 12:55

Hi all,

How can I close and delete/remove/destroy/kill/annihilate/obliterate/dispatch to bit heaven an idiotically stubborn text file, which cannot be closed?

The case:

I download two text files from a bank to the user's default download directory, then copy them to a work directory and then kill them from the download dir. So far so good. Then, in the work directory (not in any system directory):

In Button1 I read the first file with fLoadtext and show it to the user in a window so that he can visually check it before proceeding. When the user closes the window, I returntocapture.

In Button2 I open the same file, read it in a loop with fReadLine, manipulate its contents and write it to a HFSQL-file, and close it with fClose, or TRY to close it, in order to be able copy the original file to an archive directory and then delete it from the work directory.
THE PROBLEM: The file csnnot be closed, and therefore it cannot be deleted, because "it is being used by another process"!

In Button3 I do an exactly similar operation with the second text file (only the files and fields are different): Open it, read it, write it to a HFSQL-file, close it, copy it to the archive dir and then delete it. This works as documented, no problems! Why does this work? Hint: this file has not been touched with the fLoadText command like the first one!

Why can't I close and delete the first file? What's up? Who is using it? Nobody as far as I know! Unless it is PCSoft with its fLoadtext process!?!?!? Could fLoadtext leave the file open? I do not know its handle number so how can I close it? How can I force the closing of a file?

Any hints/tips/instructions will be appreciated.

Best regards
Ola

Antworten:

Have you tired... ?

hOpen(filename,foAutomaticDeletion)

von abonds - am 25.07.2015 18:51
= fClose()

What is the result when you try to fClose? Does it lie to you and say it is closed? If it does not lie, what does ErrorInfo give you for the reason it erred?

von abonds - am 25.07.2015 19:08
I checked and rechecked and tweaked the code and added error/success recording to the process.

It seems now that the file can be closed, but I cannot find any way to delete it, not even with an external file manager, until my program is closed.

fClose result = 0, which suggests that it is closed, but is it really closed?

I have not tried hOpen(filename,foAutomaticDeletion) - I want to control the process myself, and delete the file only after I know that the whole process has succeeded.

Ola

von Ola - am 28.07.2015 09:22
Finally found it.
It was my bad. I had opened the file for a second time in a sub process! I removed the other opening and now the problem seems to have disappeared. fLoadtext is innocent!

Thanks for suggestions.

Ola

von Ola - am 28.07.2015 09:53
Zur Information:
MySnip.de hat keinen Einfluss auf die Inhalte der Beiträge. Bitte kontaktieren Sie den Administrator des Forums bei Problemen oder Löschforderungen über die Kontaktseite.
Falls die Kontaktaufnahme mit dem Administrator des Forums fehlschlägt, kontaktieren Sie uns bitte über die in unserem Impressum angegebenen Daten.