Hi,
this may be a stupid question: Is there a special function to preoccupy size on the disk when writing a file? I mean, like the Windows Explorer does on copying (when I copy a big file the remaining disk size already reduces by the file's size when the explorer opens the file). I know I can open the file and fill it with zeros, then fill the real content. But this way it is written twice, so I am sure there's an API for that or something.
Pre-occupy file space
Pre-occupy file space
Good morning, that's a nice tnetennba!
PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
Re: Pre-occupy file space
It's a perfectly reasonable question — the answer is yes, you can create a sparse file, a provision which exists in NTFS and also widely used in Unix.
It is necessary to first create the file and then call DeviceIoControl http://msdn.microsoft.com/en-us/library ... 85%29.aspx Set the option FSCTL_SET_SPARSE IOCTL https://learn.microsoft.com/en-us/windo ... dfrom=MSDN
It is necessary to first create the file and then call DeviceIoControl http://msdn.microsoft.com/en-us/library ... 85%29.aspx Set the option FSCTL_SET_SPARSE IOCTL https://learn.microsoft.com/en-us/windo ... dfrom=MSDN
Re: Pre-occupy file space
Thanks, I'll look into that.
Good morning, that's a nice tnetennba!
PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
Re: Pre-occupy file space
FSUTIL can do this. So there must be an API or something... I am not good at finding it.
https://learn.microsoft.com/en-us/windo ... sutil-file
Saso
https://learn.microsoft.com/en-us/windo ... sutil-file
Code: Select all
fsutil file createnew 'file_name' 'length'
Re: Pre-occupy file space
From my archives:
It gets filled with 0 bytes.
Code: Select all
Procedure CreateEmptyFile(file$,bytes.q)
f=CreateFile(#PB_Any,file$)
If f
SetFilePointer_(FileID(f),bytes,0,#FILE_BEGIN)
ok=SetEndOfFile_(FileID(f))
CloseFile(f)
EndIf
ProcedureReturn ok
EndProcedure
Debug CreateEmptyFile("D:\1-MB-File.txt",1048576)
Re: Pre-occupy file space
Reminds me of a time when PureBasic was so small that users were forced to do this...

Code: Select all
;==================================================================
;
; Author: Rings
; Date: September 9th, 2009
;
; Typical Usage:
; If you want to appear competitive in the eyes of a user who might have concluded
; that a 30Mb download must be really something special compared to 100kb download.
; Then...Bloat away!
;==================================================================
Macro BloatMe(_LONGS_)
! jmp SR
! rept _LONGS_ counter
! {
;! byte#counter db counter
! dword#counter dd counter
! }
!SR:
EndMacro
BloatMe(100000) ; Add Bloat - (adds nearly 400 kb)
MessageRequester("BLOATING", "Created a file (this is nearly 400k in size)",0)
- It was too lonely at the top.
System : PB 6.21(x64) and Win 11 Pro (x64)
Hardware: AMD Ryzen 9 5900X w/64 gigs Ram, AMD RX 6950 XT Graphics w/16gigs Mem
System : PB 6.21(x64) and Win 11 Pro (x64)
Hardware: AMD Ryzen 9 5900X w/64 gigs Ram, AMD RX 6950 XT Graphics w/16gigs Mem