- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I have a DLL which opensa series of files (the list of files depends on the operations being executed and cannot be predicted in advance).
When an error condition occurs, I would like to be able to close all the files which have been opened by the DLL.
I suppose that doing a DO loop on unit numbers from 1 to a-very-big number and closing the opened units might work; but it certainly is not very elegant (or efficient).
Is there a way to close all the opened files at once?
Thanks,
Olivier
I have a DLL which opensa series of files (the list of files depends on the operations being executed and cannot be predicted in advance).
When an error condition occurs, I would like to be able to close all the files which have been opened by the DLL.
I suppose that doing a DO loop on unit numbers from 1 to a-very-big number and closing the opened units might work; but it certainly is not very elegant (or efficient).
Is there a way to close all the opened files at once?
Thanks,
Olivier
Link Copied
6 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello
When the process terminates, all opened files are closed.
When the process terminates, all opened files are closed.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Keep in mind that this is a DLL; If an error condition occurs (and is handled by the DLL), the DLL returns the execution to the main program, which in turns calls the DLL again (hopefully, with new parameters that do not trigger an error). So, some files might already be opened for the second call to the DLL.
Olivier
Olivier
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Is there some reason why you do not find it desirable to maintain a list of open units, and/or to restrict the unit numbers to, say, < 100 ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
In that case, why not just making the DLL check every unit before opening the file? You can write a procedure to do just that and call it right before the OPEN statement. Something like:
call close_file_if_open (foo_unit)
open (unit = foo_unit, file = ...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
There is no option to close all open files, nor is there a convenient way to get a list of units that are open. (You can loop from 0 to 21473642(or something like that) and use INQUIRE (UNIT=n,OPENED=) to see if a unit is opened, but I don't recommend that.
I agree with the suggestion that you keep track of the unit numbers you use to open files.
I agree with the suggestion that you keep track of the unit numbers you use to open files.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks to all for your answers and suggestions. It seems there is no easy shortcut. I'll have to implement a simple file tracking mechanism then.
Olivier

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page