That's the way to do it.
Code: Select all
#include "crt.bi"
type widestring as wstring * 10000
Function filelength(filename As wstring Ptr)As Long
Dim As wstring * 4 k="r"
Var fp=_wfopen(filename,@k)
If fp = 0 Then Print "Error opening file":Sleep:End
fseek(fp, 0, SEEK_END)
Var length=ftell(fp)
fclose(fp)
Return(length)
End Function
Sub savefile overload(content As String ,filename As wstring Ptr)
Dim As wstring * 4 k="wb"
Var fp= _wfopen(filename,@k)
If fp = 0 Then Print "Error opening file":Sleep:End
fwrite(@content[0], 1, Len(content), fp)
fclose(fp)
End Sub
Sub loadfile overload( content As String,filename As wString Ptr)
Var l=Filelength(filename)
content=String(l,0)
Dim As wstring * 4 k="rb"
Var fp= _wfopen(filename,@k)
If fp = 0 Then Print "Error loading file ";filename:Sleep:End
fread(@content[0], 1,l, fp)
fclose(fp)
End Sub
Sub savefile(content As wString ,filename As wstring Ptr)
Dim As wstring * 4 k="wb"
Var fp= _wfopen(filename,@k)
If fp = 0 Then Print "Error opening file":Sleep:End
fwrite(@content[0], 2, Len(content), fp)
fclose(fp)
End Sub
Sub loadfile(content As wString,filename As wString Ptr)
Var l=Filelength(filename)
content=wString(l,0)
Dim As wstring * 4 k="rb"
Var fp= _wfopen(filename,@k)
If fp = 0 Then Print "Error loading file ";filename:Sleep:End
fread(@content[0], 2,l, fp)
fclose(fp)
End Sub
Function exists(filename As wString Ptr) As boolean
Dim As wstring * 4 k="r"
Var fp= _wfopen(filename,@k)
If fp=0 Then
Return false
Else
fclose(fp)
Return true
End If
End Function
dim as wstring * 200 txt=wchr(915,949,953,940,32,963,959,965,32,954,972,963,956,959,962)
txt+=wchr(32,45,45,32,105,115,32,103,114,101,101,107,32,102,111,114,32,104,101,108,108,111,32,119,111,114,108,100)
print txt
savefile(txt,"myfile.txt")
dim as widestring contents
loadfile(contents,"myfile.txt")
print "from file"
print contents
print "Length of file "; filelength("myfile.txt")
sleep
kill "myfile.txt"
if exists("myfile.txt") then print "Please delete file" else print "deleted"
sleep