Hello:
is there any equivalent to the win api SetEndOfFile_()?
thanks
equivalent to SetEndOfFile_()?
Re: equivalent to SetEndOfFile_()?
SetEndOfFile_() of which file?
You surely know that for security reasons you cannot access local files from your browser?
Greetings ... Peter
You surely know that for security reasons you cannot access local files from your browser?
Greetings ... Peter
Re: equivalent to SetEndOfFile_()?
The following function truncates the file at the current file pointer location (FileSeek()).morosh wrote:is there any equivalent to the win api SetEndOfFile_()?
You can truncate a file (make it smaller), but you can't extend the file size (make it larger).
Code: Select all
Procedure TruncateFile(file)
!var f;
!if (f = spider.file.objects.Get(v_file)) f.size = spider_Loc(v_file);
EndProcedure
file = CreateFile(#PB_Any,"",0)
If file
WriteString(file,"0123456789",#PB_Unicode)
Debug "Length of file: " + Lof(file)
Debug "Current file pointer: " + Loc(file)
FileSeek(file,8)
TruncateFile(file)
;WriteString(file,"Hello!",#PB_Unicode)
;WriteWord(file,0)
Debug "Length of file: " + Lof(file)
Debug "Current file pointer: " + Loc(file)
export = ExportFileMemory(file)
If export
Debug "-----"
Debug "Length of memory: " + MemorySize(export)
Debug PeekS(export,0,MemorySize(export),#PB_Unicode)
EndIf
CloseFile(file)
EndIf
cya,
...Danilo
...Danilo
Re: equivalent to SetEndOfFile_()?
Renamed SetEndOfFile() to TruncateFile(), so it is compatible with PureBasic.
cya,
...Danilo
...Danilo
Re: equivalent to SetEndOfFile_()?
Thank you Danilo
Perfect, exactly what I'm searching for.
By the way, I need also to CopyFile which is simple to implement (copying line by line), but is there something shorter with JS.
Also later I need to delete temporary files, no delete actually available
Regards
Perfect, exactly what I'm searching for.
By the way, I need also to CopyFile which is simple to implement (copying line by line), but is there something shorter with JS.
Also later I need to delete temporary files, no delete actually available
Regards
Re: equivalent to SetEndOfFile_()?
What type of files do you work with, morosh? #PB_LocalStorage files?
Looks like DeleteFile() is missing from SB. For now you could overwrite it using CreateFile():CloseFile() to create a new file with size 0.
EDIT:
Looks like DeleteFile() is missing from SB. For now you could overwrite it using CreateFile():CloseFile() to create a new file with size 0.
EDIT:
Code: Select all
;
; SpiderBasic 2.30 - Delete a file that was created using '#PB_LocalStorage' flag.
;
; ref: https://localforage.github.io/localForage/
;
Procedure DeleteFile(filename.s, flag.i = #PB_LocalStorage)
If flag = #PB_LocalStorage
!LocalForage.removeItem("sbfs_" + v_filename);
EndIf
EndProcedure
cya,
...Danilo
...Danilo
Re: equivalent to SetEndOfFile_()?
thank you Danilo
my files are on the server side, sometimes I need to do some processing, so I need to create a temporary file, fill it correctly, then copy it to the main file, then delete it (always server side).
Regards
my files are on the server side, sometimes I need to do some processing, so I need to create a temporary file, fill it correctly, then copy it to the main file, then delete it (always server side).
Regards