Jump to content

How to do a VBScript on adding dummy files?


Recommended Posts

Simply put, I wish to come up with a script that can create a dummy file padded up to the size of my choosing (with whatever characters used). Maybe one that can work in a command line script or whatever.

However my knowledge on VBScript isn't all that great and attempting to google for the info I need has turned out to be fruitless. There could anyone help out pretty please?

Cheeeeers.

Link to comment
Share on other sites


I wish to come up with a script that can create a dummy file padded up to the size of my choosing

Windows already has that built-in:

fsutil file createnew c:\path\to\whatever_file.ext 12345

where 12345 is the size of the file you want created, in bytes.

Link to comment
Share on other sites

Here's a batch file example not using fsutil as above.

To use it use your file size in bytes as the first parameter and optionally your chosen filename as an additional parameter.

e.g. dummy.cmd 213 MyDummy

The filename DummyFile will be used if you elect not to include the second parameter.

dummy.zip

Link to comment
Share on other sites

  • 2 weeks later...

Well while that's a well-thought out batch file there, it's not very friendly when it comes to space and time, due to all the various temp files and the endless whirring by the HD. Thank you for teaching me a bit more about command functions anyway.

Are you guys *sure* VBScript is incapable of doing dummy work itself? I always imagined it to be quite magic and capable of more than CMD.

Link to comment
Share on other sites

Are you guys *sure* VBScript is incapable of doing dummy work itself? I always imagined it to be quite magic and capable of more than CMD.

No one ever said it can't (I only pointed out the standard tool to do this, built right into Windows -- why reinvent the wheel? Yes, I *am* lazy, why do you ask?) And yes, it's definitely a LOT more capable than bat/cmd files (then again, pretty much everything is).

As for the vbscript (or using anything else), well, it depends how you want it to work, like how you expect to tell it what characters to use. It's trivial to do, we just need to know what you want.

Link to comment
Share on other sites

Here try this vbs script and see if it what you want it to do.

Save As MakeDummy.vbs

Option Explicit
Dim Act :Set Act = CreateObject("Wscript.Shell")
Dim Fso :Set Fso = CreateObject("Scripting.FileSystemObject")
Dim File, NameFile, SizeFile, R1
FileName()

If NameFile = "" Then
R1 = MsgBox("There was no file name enter" & vbCrLf & _
"Did you want to continue?" ,4132,"Error No File Name")
If R1 = 6 Then FileName()
If R1 = 7 Then WScript.Quit
Else
FileSize()
If SizeFile = "" Then
R1 = MsgBox("There was no file size enter" & vbCrLf & _
"Did you want to continue?" ,4132,"Error No File Size")
If R1 = 6 Then FileSize()
If R1 = 7 Then WScript.Quit
Else
MakeFile()
End If
End If

Function FileName()
NameFile = InputBox("Please type in the file name and it extention", "File Name", "", 125,125)
End Function

Function FileSize()
SizeFile = InputBox("Please type in the file size in bites", "File Size", "", 125,125)
End Function

Function MakeFile()
Dim Ts
Set Ts = Fso.CreateTextFile(Fso.GetFolder(".") & "\" & NameFile)
Set File = Fso.GetFile( Fso.GetFolder(".") & "\" & NameFile)
Do Until Int(File.Size) > Int(SizeFile)
WScript.Echo File.Size
Ts.WriteLine "ABCDEFRGHIJKLMNOPQRSTUVWXYZ1234567890"
Loop
Ts.Close
End Function

Link to comment
Share on other sites

Oooooh, ta for this. I've had to re-adapt it slightly (didn't like the the pop-up window reporting on size a gajillion times over), but I seem to have hit an annoying barrier at the moment regarding getting the file-size exact. At the moment it ends up generating a file that's slightly over the size you specify in the box because of the ">" setting, but attempting to use "=" instead seems to make the script keep working on the file endlessly, going way above the limit and showing no signs of stopping. It's strange because "=" seems to be a perfectly valid setting understood by Windows Script (after googling around for info). Is it just incompatible with "int(File.Size)"?

To give you a good idea, here's a simple example script coded to generate a specified file with a specified size limit, and writing one character at a time on a loop:

Option Explicit
Dim Act :Set Act = CreateObject("Wscript.Shell")
Dim Fso :Set Fso = CreateObject("Scripting.FileSystemObject")
Dim File, SizeFile
FileSize()
Function FileSize()
SizeFile = "100000"
End Function
Dim Ts
Set Ts = Fso.CreateTextFile("z.zzz", True)
Set File = Fso.GetFile("z.zzz")
Do Until Int(File.Size) = Int(SizeFile)
Ts.Write "ÿ"
Loop
WScript.Echo "Done!"
Ts.Close

Any way to make it honour the "=" properly?

Link to comment
Share on other sites

This will create a 1 GB file, full of spaces, called mydummy in the same location as the script, it uses your favoured language but isn't particularly quick.



Set DummyFile = WScript.CreateObject("Scripting.FileSystemObject").CreateTextFile("MyDummy", True)
For i=1 to 1024
DummyFile.Write Space(1024*1024)
Next
DummyFile.Close

You will obviously need to make sure that there's sufficient space in order to create the file.

Another option, would also be to use the Windows Resource Kit tool, CreateFil.exe which also fills the file with spaces.

Link to comment
Share on other sites

Oooooh, I like! Although there's yet again something I'm puzzled about.

I assumed where it says "Space", you could replace it with a character of your choice - but WScript generates errors in that part whether I use quotations or not. Yet the write function doesn't look that much different from one in the script I showed above. Maybe it just doesn't like having a sum function next to it?

Maybe it would help if I explain a bit more about what I'm trying to achieve - a script that goes by bytes rather than megabytes, and which determines how many bytes the dummy should be exactly by how much space the specified folder takes up out of a total of, say, a 700Mb CD capacity, and which inputs a specified character of choice. Am I dreaming too wildly here? ;)

Edited by Marztabator
Link to comment
Share on other sites

Not really, my only problem with your 'dream' is that I've no understanding whatsoever why you feel the need to specify the character used to fill a dummy file in order to pad out your file collection.

Link to comment
Share on other sites

  • 7 years later...

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
  • Recently Browsing   0 members

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