way to create file of specific size filled with nothing?

Walleye

Banned
Dec 1, 2002
7,939
0
0
how would i create a file of a specific size, filled with nothing but crap?

i got plans :evil:
 

Walleye

Banned
Dec 1, 2002
7,939
0
0
i suppose i could open up wordpad and hold down the "L" key for a long time, but that'd take too long.
 

MikeMike

Lifer
Feb 6, 2000
45,885
66
91
friend once wrote a prgram to fill the drive, wrote a .txt file full of junk, in multiple locations until the drive was full. only worked on the c drive though
MIKE
 

MustISO

Lifer
Oct 9, 1999
11,927
12
81
I have a program that does that. Basically creates padded files. There's nothing in them but the file system sees them as whatever size you specify. It's a simple command line utility.
 

Walleye

Banned
Dec 1, 2002
7,939
0
0
Originally posted by: nourdmrolNMT1
friend once wrote a prgram to fill the drive, wrote a .txt file full of junk, in multiple locations until the drive was full. only worked on the c drive though
MIKE

i dont have a C: drive.

i just want to make a file filled with a bunch of random crap for a length i specify in bytes.
 

Walleye

Banned
Dec 1, 2002
7,939
0
0
Originally posted by: Bootprint
Something like this might work for you.

well... i'm really trying to create 1 file of a specific length with nothing but crap inside. i'll manually edit in some file headers with wordpad or something. but beyond that, nothing but crap using every possible character on the keyboard.
 

Mucman

Diamond Member
Oct 10, 1999
7,246
1
0
ok... you could easily do this in C++ then... it would only be a couple line perl script though. Only a couple of more lines if it's C++
 

Beau

Lifer
Jun 25, 2001
17,730
0
76
www.beauscott.com
It's slower than tar, but it works:
-------------------------------------------------------------------------------------------

N/M buggy. I'll fix it.
 

glugglug

Diamond Member
Jun 9, 2002
5,340
1
81
cat /dev/random | head -c [number of bytes] > filename

cat /dev/zero | head -c [number of bytes] > filename also works if file full of zeros is ok.


or you could do this:

#include <ofstream>
#include <string>
using namespace std;

int main(int argc, char *argv[])
{
long numbytes = atol(argv[1]);
ofstream outfile(argv[2]);
outfile << string(numbytes,'X');
return 0;
}
 

Beau

Lifer
Jun 25, 2001
17,730
0
76
www.beauscott.com
fixed it. Make it into a vbs file (it's A LOT faster now, and you can use calculations in the input box like 1024^2 to make a 1 mb file.):
===========================
Sub Main()
     Dim intSize
     dblSize = CDbl(Eval(InputBox("How big do y'ant it? (in bytes)")) + 0)
     Continue = msgbox("Are you sure you want to create a " & dblSize & "b file?", vbOkCancel)
     If Continue = vbCancel Then Exit Sub

     Dim objFSO, objTextFile, strFileName
     Set objFSO = CreateObject("Scripting.FileSystemObject")

     Randomize
     
     Do While Len(strFileName) < 8
          strFileName = strFileName & Chr(Int((90 - 65 + 1) * Rnd + 65))
     Loop
     
     Set objTextFile = objFSO.CreateTextFile(strFileName & ".txt")
     
     Dim sTemp, i
     i = 0
     
     Do While i < dblSize
          i = i + 1
          sTemp = sTemp & (Chr(Int((254) * Rnd + 1)))
          if (i Mod(1000)) = 0 Then 'dump every 1000 characters
               objTextFile.Write(sTemp)
               sTemp = ""
          End if
     Loop
     
     objTextFile.Write(sTemp)

     Set objTextFile = Nothing
     Set objFSO = Nothing
     MsgBox("Finished.")
End Sub


Call Main
 

Nothinman

Elite Member
Sep 14, 2001
30,672
0
0
dd if=/dev/urandom of=/path/to/file bs=1024k count=10

That would give you a 10M file, adjust numbers as appropriate.

Or you could create a sparse file (100M this time) with dd if=/dev/urandom of=/path/to/file seek=100 count=1 bs=1M
 

Walleye

Banned
Dec 1, 2002
7,939
0
0
while this does exactly what i want, it makes an overflow error on the size files i'm trying to make.



i tried it on a 6000 kb file, and it worked.

but i'm trying to make a 700 mb + file, and it's giving a runtime error.
 

Beau

Lifer
Jun 25, 2001
17,730
0
76
www.beauscott.com
Originally posted by: Walleye
while this does exactly what i want, it makes an overflow error on the size files i'm trying to make.



i tried it on a 6000 kb file, and it worked.

but i'm trying to make a 700 mb + file, and it's giving a runtime error.

Try it now. I updated the code a bit. Does it actually start to run on the 700mb file? cuz it worked on mine. I let it go to about 60mb of the 700mb before I killed it.

also, what are you entering in fo rthe 700mb file. Should be 700 * (1024^2).
 

Walleye

Banned
Dec 1, 2002
7,939
0
0
Originally posted by: Beau
Originally posted by: Walleye
while this does exactly what i want, it makes an overflow error on the size files i'm trying to make.



i tried it on a 6000 kb file, and it worked.

but i'm trying to make a 700 mb + file, and it's giving a runtime error.

Try it now. I updated the code a bit. Does it actually start to run on the 700mb file? cuz it worked on mine. I let it go to about 60mb of the 700mb before I killed it.

also, what are you entering in fo rthe 700mb file. Should be 700 * (1024^2).

alright. now, yeah, it does work. i havent let it run for the 700 mb yet. for the test run i killed it at 30. but it looks like it's gonna work.

thanks :)
 

Beau

Lifer
Jun 25, 2001
17,730
0
76
www.beauscott.com
Originally posted by: Walleye
Originally posted by: Beau
Originally posted by: Walleye
while this does exactly what i want, it makes an overflow error on the size files i'm trying to make.



i tried it on a 6000 kb file, and it worked.

but i'm trying to make a 700 mb + file, and it's giving a runtime error.

Try it now. I updated the code a bit. Does it actually start to run on the 700mb file? cuz it worked on mine. I let it go to about 60mb of the 700mb before I killed it.

also, what are you entering in fo rthe 700mb file. Should be 700 * (1024^2).

alright. now, yeah, it does work. i havent let it run for the 700 mb yet. for the test run i killed it at 30. but it looks like it's gonna work.

thanks :)

No problem.
 

PushHands

Senior member
May 22, 2002
990
0
0
$numbytes = 1024 # length of file in bytes
open JUNK, "<filename.junk";
for ($i = 0; $i < $numbytes; $i++){
print JUNK chr(0);
}
close JUNK;

That will create a file called "filename.junk" with the specified number of bytes, filled with 0s.

BTW, this is notfred posting from my friend's PC.