Author Topic: do we need a similar function to PB FREEFILE?  (Read 1063 times)

0 Members and 1 Guest are viewing this topic.

chrisc

  • Guest
do we need a similar function to PB FREEFILE?
« on: April 25, 2018, 08:08:58 AM »
In PB there is a FREEFILE function which gets the next available file number or channel
before we can open a new file

http://manmrk.net/tutorials/basic/PowerBASIC/pbcc/freefile_function.htm

which i think is not needed in O2.   am i correct?


Charles Pegge

  • Guest
Re: do we need a similar function to PB FREEFILE?
« Reply #1 on: April 25, 2018, 10:24:32 AM »
If you are using whole files then we have GetFile and PutFile which do not require handles. Otherwise, a sys variable is used as a file handle:

Code: [Select]
use corewin
string s
sys e,f
'EQUIVALENT TO: S=GETFILE "T.TXT"
f=fopen "t.txt","r" 'open for reading
print f             'file handle or null
fseek f,0,2         'end of file
e=ftell f           'get position
print e             'length of file
fseek f,0,0         'beginning of file
s=nuls e            'create buffer to fit
fread s,1,e,f       'load buffer
fclose f            'close file

chrisc

  • Guest
Re: do we need a similar function to PB FREEFILE?
« Reply #2 on: April 25, 2018, 11:03:14 AM »
Thanxx a lot Charles

O2 is much better than the PB  FREEFILE and other file functions as it involves more code lines to read a file

in your program above, i notice that you can read the entire file into a buffer string s

then what would be the maximum file size that can be read into this string s ?   

is this process called a Binary file read ?

Charles Pegge

  • Guest
Re: do we need a similar function to PB FREEFILE?
« Reply #3 on: April 25, 2018, 01:32:08 PM »
For GetFile and PutFile, there is no distinction between binary and text, and the theoretical upper limit for an OLEstring is around 2 Gig: 0x7FFFFFFF, so you will have to split your DVD files down a bit for editing :)