What exactly can I expect if I set a filepointer beyond the current EOF ??
Will the file "instantly" grow to encompass the new EOF?
If this is not the case, can anyone point me at information regarding SPARSE please?

TIA, Homer.
Posted on 2005-02-02 04:52:51 by Homer
> Will the file "instantly" grow?

No. You must do a Writefile or SetEndOfFile first.
Posted on 2005-02-02 07:46:01 by japheth
Much appreciated .. but hang on a minute, SetEndOfFile sets the new EOF to the current fileposition (although the docs mention that it can be used to extend a file??!?) but SetFilePosition cannot set the current fileposition beyond the current EOF - this sounds like a chicken-egg situation !!
What I really want to do is create a dummy file of known 64bit length, without having to write to the file per se.
Back in the DOS days it was possible to set a file's size... how can I create a file of known size without writing each and every byte of data?
Posted on 2005-02-02 22:08:32 by Homer
Nevermind, I've realized that SetFilePointer is succeeding although the file won't grow until SetEndOfFile or WriteFile is called.
I added method SetEOF to my FStream class.
The following code created a 20kb file "instantly"..

mov pfile, new(FStream)             ;Create FStream object for file io

set pfile as FStream ;<-- use dot calling convention
pcall pfile.Open,CTEXT("Dummy.txt") ;<-- Create/Open a file
pcall pfile.SetPointer,20000,0 ; <-- Low, High
pcall pfile.SetEOF ;Like magic :)
delete pfile ;Destroying object Closes the file


but if I change the filesize to say 20000,2 (large file) then the filesize stays at 0.

SetEndOfFile is only useful for 32bit files? A bug?
Anyhow, if I replace the SetEOF with code to write something, it works.

mov pfile, new(FStream)             ;Create FStream object for file io

set pfile as FStream ;<-- use dot calling convention
pcall pfile.Open,CTEXT("Dummy.txt") ;<-- Create/Open a file
pcall pfile.SetPointer,20000,2 ; <-- Low, High
pcall pfile.Put, CTEXT("X"),1 ; Write a byte
delete pfile ;Destroying object Closes the file


That created a file which is hex 2,0000,0000 + dec 20,001 bytes in size... and did so "instantly" 8)
If I just decrement my desired size I can work around it.
Anyway, thanks a bunch :)
Posted on 2005-02-02 22:37:38 by Homer
You only get "instant growth" on NTFS filesystems, iirc - on fat32 creating a multi-gig file this way will still take a while :)
Posted on 2005-02-03 06:02:04 by f0dder
I have no problem with that - DOS based operating systems allow you to set the filesize by hand, as I mentioned earlier - it'll mean casecoding by operating system.. if/when I get complaints I'll bother.
Posted on 2005-02-03 06:12:31 by Homer
I saved this as a .txt file from some FAQ site for windows:
If you need to create a file of a certain size and the file contents don't matter, you can use the Fsutil command as follows:

fsutil file createnew <name of file> <size in bytes>

For example,

fsutil file createnew d:\temp\1mbfile.txt 1000000

creates a 1MB file named 1mbfile.txt in the d:\temp folder. I've successfully used this command to create a very large file to reduce the amount of free space when I was using a buggy installation program that couldn't address too much free space.
Posted on 2005-02-03 07:31:50 by DaRetard