Sign in to follow this  
Followers 0
usera

Create a big size file

8 posts in this topic

Greeting,

I am looking for a way to create a big size (like 100mb) file.

The content of the file could be anything not important. the important is the size need to be exactly and big.

what is the best way.

Thanks

usera

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

This is a strange request. What will you do with it after you create it?

Here's a slow method, and I'm not sure of the exact size you will get.

Local $data = ""
While StringLen($data) < 10000000
    $data &= Chr(Random(32, 126, 1))
WEnd
For $i = 1 To 100
    FileWrite("bigFile.txt", $data)
Next

oops, I missed something. Okay, something like this would be faster:

Local $data = "00000000000000000000000000000000"
While StringLen($data) < 1000000
    $data &= $data
WEnd
For $i = 1 To 100
    FileWrite("bigFile.txt", $data)
Next
Edited by czardas

Share this post


Link to post
Share on other sites

A quick google search for "create big size file" finds "fsutil"

$Size_In_MB = 200
$Size = Number(1024*1024*$Size_In_MB)
RunWait('fsutil file createnew NewFile ' & $Size, @DesktopDir, @SW_HIDE)
If Not FileExists(@DesktopDir & '\NewFile') Then Exit MsgBox(0, 'ERROR', 'Cannot create NewFile')
$ReadSize = FileGetSize(@DesktopDir & '\NewFile') / 1024 / 1024
Msgbox(32, 'File Created', 'NewFile size: ' & $ReadSize & ' MB')

Share this post


Link to post
Share on other sites

Or use FileSetPos()...

#include <Constants.au3>

Local Const $sFile = "test.txt"
Local $hFile = FileOpen($sFile, 2)

; Check if file opened for writing OK
If $hFile = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

FileSetPos($hFile, (1024*1024*100)-1, $FILE_BEGIN)
FileWrite($hFile, 0)

; Close the handle.
FileClose($hFile)

Share this post


Link to post
Share on other sites

What is it for? Just curious.


Hi ;)

Share this post


Link to post
Share on other sites

What is it for? Just curious.

Thanks for ask, the reason for this, is a software (utility) need test for exactly size file for open and read it and have to be big

Thanks

usera

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0