Resize a File in Command Prompt?
I don't believe the functionality exists natively in the DOS shell, I suspect you need to use another program to get the job done. Here are a few possibilities:
There is a tool called Trunc which claims to do exactly what you are after:
Trunc is a Windows command-line app to truncate files to a specified size. Also usable to enlarge a file.
You'll have to try it out to find out exactly how the file is getting padded out (e.g. with zeros or garbage) but otherwise this seems to fit the bill of what you are asking for.
fsutil is a Windows XP and above system tool that appears to have some functionality that might help. Specifically the
fsutil file
subcommand appears to be able to create, set length and also zero fill files.Specifically:
fsutil file createnew "C:\temp\myfile" 1024
Will create a zero filled 1024 byte file, but I cannot see a way to truncate the file. There is a command that sets valid data length, but it does not appear to modify the EOF marker as:
Using setvaliddata
In NTFS, there are two important concepts of file length: the End of File (EOF) marker and the Valid Data Length (VDL). The EOF indicates the actual length of the file. The VDL identifies the length of valid data on disk. Any reads between VDL and EOF automatically return 0 in order to preserve the C2 object reuse requirement.
UVHD is a hex editor that appears to have the functions you are asking for. The only problem is that it only works under Windows/SFU (Services for Unix) and not DOS. What that actually means to an end user I don't actually know, but I have a vague suspicion that SFU was dropped in Vista and Win 7.
copy /Y nul: file.txt
For setting to 0 bytes only, of course.
try my BSD truncate build for Windows.
EDIT: it is not working with files >2GB.
Alternatives that works well with big files:
- trunc.exe (previously on google code, now mirrored in softpedia)
- chsize32 (closed source)