Create file with specified size

Yesterday I run into very strange problem with one of my friends – Echo. stopped working.


 In batch scripts, you use Echo to output something to screen – and of course you can redirect it to file.


By using Echo. (mind the dot), you specify that you want to output empty line. So if you want to create empty file from batch, you can use Echo. > c:\Temp\Empty.txt


Yesterday one script stopped working – Echo. was not working. It was working for everything else (including log files etc), just not for creating files in one folder. I have absolutely NO IDEA how that was possible (and if someone does, share any ideas, I am very curious about this one).


I remembered of less known feature from FSUtil – FSUtil can create for you empty file with predefined size. And it worked:


FSUtil File CreateNew C:\Temp\Empty.txt 0


In my case I used it only as alternative method because Echo. failed, however it can be useful if you want to benchmark performance or do something similar.


For example if I want to create 10 files with 10GB size, I would run following command:


for /l %i IN (1,1,5) Do FSutil File CreateNew C:\Temp\PerfTest\Test%i 1073741824


This would create 5 files with 10GB size. What I like about it that all files are created within miliseconds.

2 thoughts on “Create file with specified size”

  1. Hey Martin, (love the site… good stuff abounds)

    In reference to your issue with “Echo.” Since I don’t have the script to look at, but I can relate to you one experience that occasionally bites me.

    I’ve seen some really goofy things (read many hours of troubleshooting) result from copy-and-paste from a wide-character application into what should be a text file. You may want to look at that “.” in hex mode to see that it is actually 2E or 2E00.

    I hope that you solve this personally perplexing issue.

    -Jim

Leave a Reply

Your email address will not be published. Required fields are marked *


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>