Appending extra data to Files
Posted: Mon Feb 19, 2007 5:58 pm
Code updated for 5.20+
Requires NTFS 5 File-System (Windows 2000 and later).
Requires NTFS 5 File-System (Windows 2000 and later).
Code: Select all
;
;
; ---Important:
; This example requires NTFS 5 Filesystem (Windows 2000 and later)
;
;
; Create test file (12 bytes)
;
If CreateFile(1, "Test.txt")
WriteString(1, "Hello World!", #PB_Ascii)
CloseFile(1)
Debug FileSize("Test.txt")
EndIf
;
; Append some extra information to the file
; The data is written to a "stream".
; You can have multiple streams with different names for every file.
; Just add the name of your stream after the colon.
;
If OpenFile(1, "Test.txt:ExtraData")
WriteString(1, "Hello Extra Data!")
CloseFile(1)
EndIf
;
; The file size is STILL 12 bytes, but the extra data is there...
;
Debug FileSize("Test.txt")
;
; ...so read the extra data from the file:
;
If ReadFile(1, "Test.txt:ExtraData")
Debug ReadString(1, #PB_Ascii)
CloseFile(1)
EndIf
;
; Remove the additional data from the file.
;
DeleteFile_("Test.txt:ExtraData")