Jump to content

Create a big size file


usera
 Share

Recommended Posts

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

Link to comment
Share on other sites

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
Link to comment
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')

Link to comment
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)
Link to comment
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)

works and thanks

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...