What is a file number?

I am working on some C # code that was previously converted from VB6 and it makes a lot of IO files. In all of this, I see this:

  fn = VBNET.FileSystem.FreeFile();

... then VBNET.FileSystem.FileOpen (), some IO file, and then VBNET.FileSystem.FileClose ().

The call to FreeFile () generates the "file number" that is required to open the file. But what is the file number and how do you release it back to the system when you're done with it?

The documentation at http://msdn.microsoft.com/en-us/library/microsoft.visualbasic.filesystem.freefile.aspx does not seem to say, but it says that an exception will be thrown if "more than 255 files are used," which implies that it would be nice to release them when I finished with them.

NB . I understand that it is better to use IO file libraries, but that’s what we are stuck for as long as we don’t have the resources to rewrite this stuff, so I just want to understand that.

+4
source share
2 answers

These VB6 commands (FreeFile, FileOpen, FileClose, LOF, etc.) were present at least in QBasic. I expect the file number was originally an MS-DOS file descriptor.

A quick Google search showed the following links:

QBasic ( ), FileOpen . FileClose .

FreeFile : , () # 1 open, OPEN "C:\DOS\RUN" FOR INPUT AS #1 FreeFile. CLOSE #1

, VB6. , .NET VB6File. FileSystem.vb

+5

BASIC, pre-objects, I/O , , , . , . , API Windows, BASIC .

, - :

OPEN #1, "path\to\file"
PRINT #1, "Stuff I want in the file"
CLOSE #1

, , ..

, , .., . , , - , , , .

FreeFile - VB . FreeFile , , . :

I = 0
WHILE ALREADYOPEN(#I) 
  I = I + 1
WEND
OPEN #I, "path\to\file"
PRINT #I, "stuff to go into file"
CLOSE #I

FreeFile , , , , , . I/O : , , / .

+3

Source: https://habr.com/ru/post/1534903/


All Articles