Создание файла с помощью Api

Этот пример создает практически пустой файл размером 6 гб.
Платформа: Windows.
Автор:  Vincent DeCampo.

 

'**** Creating large files quickly ****
'by Vincent DeCampo
'
#INCLUDE "windows.bi"


/'
   Redefine SetFilePointerEx To Get rid of LARGE_INTEGERs
'/
#Undef SetFilePointerEx

Extern "windows" Lib "kernel32"
Declare Function SetFilePointerEx (Byval As HANDLE, Byval As Ulongint , Byval As Ulongint Ptr, Byval As Uinteger) As Integer

End Extern

   
Dim As HANDLE fh
Dim As Ulongint fpointer,newloc
   
   fpointer = 6*1024*1024*1024! '6Gb
   fh  = CreateFile("test.dat", GENERIC_READ Or GENERIC_WRITE, FILE_SHARE_READ Or FILE_SHARE_WRITE, 0, OPEN_ALWAYS, 0, 0)
   Print ("Attempting to set file size to "+Str(fpointer))
   If SetFilePointerEx(fh,fpointer,@newloc,FILE_BEGIN) Then

      Print ("New location reported as "+Str(newloc))
      SetEndOfFile(fh)
   Else

      Print ("Error Code=" & GetLastError())
   End If

   CloseHandle(fh)

Print "Done"
Sleep