Date: 02-16-2022
Return to Index
created by gbSnippets
'Sometimes a programmer needs a really large file to use in testing how
'an application handles large files. The PowerBASIC SetEOF statement
'makes this very easy.
'Primary Code:
'SetEOF truncates a file at a byte location, but that locations can
'be longer than the current file size. Uses SEEK statement to
'set the current position at which SetEOF establishes as the file size.
Open NewFile$ For Binary As #1
Seek #1, FileSize& + 1 'when SetEOF truncates, it includes the current position
Seteof #1
Close #1
'Compilable Example: (Jose Includes)
'This example does not ask for permission to overwrite an existing file.
'When the example is run, look in Explorer to verify the new size of the file.
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "Win32API.inc"
Global hDlg As Dword
Function PBMain() As Long
Dialog New Pixels, 0, "Test Code",300,300,200,200, %WS_OverlappedWindow To hDlg
Control Add Button, hDlg, 100,"Push", 50,10,100,20
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
If CB.Msg = %WM_Command AND CB.Ctl = 100 AND CB.Ctlmsg = %BN_Clicked Then
CreateEmptyFile("myfile2.txt", 750000)
MsgBox "File size changed.", %MB_OK+%MB_IconInformation, "Set File Size"
End If
End Function
Sub CreateEmptyFile (NewFile$, FileSize&)
Open NewFile$ For Binary As #1
Seek #1, FileSize& + 1 'when Seteof truncates, it includes the current position
Seteof #1
Close #1
End Sub
'gbs_00143
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm