前のトピック: ファイルの内容に関する関数次のトピック: CreatePipe - パイプの作成


CloseFile - ファイルのクローズ

NetWare、Symbian OS、UNIX、Windows、および Windows CE で有効です。

CloseFile 関数は、OpenFile または CreateFile への呼び出しから取得されたファイル ハンドルに関連するファイルを閉じます。

関数の形式

CloseFile(handle as Integer) as Boolean
handle

OpenFile または CreateFile の呼び出しから取得されたファイル ハンドル。

この関数が正常に終了すると、TRUE が返されます(ゼロ以外)。 この関数に失敗すると(たとえば、ハンドルが有効なオープン ファイルのハンドルでない場合)、この関数は FALSE を返します。

例:

この例では、CONFIG.SYS ファイルのバックアップが作成されます。

Dim fIn, fOut as integer   ' Declare file handles
Dim OneLine as string     ' String to hold one line

' First open the Input file...

fIn=OpenFile("C:\CONFIG.SYS",O_READ)
if fIn<0 then
	MessageBox("Unable to open input file","Error")
	Goto End
End if

' ...Then create the output file...

fOut=CreateFile("C:\CONFIG.BAK")
if fOut<0 then
	MessageBox("Unable to create output file","Error")
	Goto End

End if

' ...Copy lines until none left...

while Not(Eof(fIn))
	if ReadFile(fIn,OneLine) then WriteFile(fOut,OneLine)
wend

' ...Close Files, and signal success.

CloseFile(fIn)
CloseFile(fOut)
MessageBox("A backup of the CONFIG.SYS file was created","MyScript")

end: