Creating dummy files

Hi guys,

I have tried to create a set of "dummy" files using the FileType command. As I've had no success so far, I thought I'd ask first if this is possible. By dummy I mean physical files with the .jpg extension, which are basically 0 bytes in size and are not jpgs at all (I hope that makes sense).

I have a text list of the filename I need to create so it's just the Opus syntax required. Any help would be much appreciated.

Regards

blueroly

Have you seen How to Create New/Empty Files in the FAQ?

I did but it wasn't making sense. Now that I've read it properly though, all is good. Thanks Leo.

Here's my solution for anyone interested.


I have the following button that creates dummy files with specified size, but this command requires to enter file size in bytes. It's uncomfortably calculate every time I need create a file.
Is there a way to automatically multiply the input values in 1024, 1048576 or 1073741824, depending on what file size should be (KB, MB or GB)?

cd {s} @runmode hide @set size={dlgstringS|Enter the file size in bytes:|{clip}} {alias|system}\fsutil.exe file createnew dummy_{date|yyyy-MM-dd}_{time|HH.mm.ss} {$size}

<?xml version="1.0"?> <button backcol="none" display="label" separate="yes" textcol="none"> <label>Create Dummy File...</label> <icon1>#empty</icon1> <function type="normal"> <instruction>cd {s}</instruction> <instruction>@runmode hide</instruction> <instruction>@set size={dlgstringS|Enter the file size in bytes:|{clip}}</instruction> <instruction>{alias|system}\fsutil.exe file createnew dummy_{date|yyyy-MM-dd}_{time|HH.mm.ss} {$size}</instruction> </function> </button>

[quote="YankeeZulu"]I have the following button that creates dummy files with specified size, but this command requires to enter file size in bytes. It's uncomfortably calculate every time I need create a file.
Is there a way to automatically multiply the input values in 1024, 1048576 or 1073741824, depending on what file size should be (KB, MB or GB)?[/quote]

Opus 11 lets you write button code in Javascript or VBScript, which would be the best way to do that now.

I tried to write a script, but it does not work (

[code]Option Explicit

Function OnClick(ByRef ClickData)

Dim dlg
Dim multiplier
Dim output
Dim stringlength
Dim size
Dim unit

Set dlg = ClickData.Func.Dlg

dlg.title = "Create dummy file"
dlg.message = "Enter the file size:"
dlg.buttons = "OK|Cancel"
dlg.default = ""
dlg.Select = True
dlg.max = 15

stringlength = Len(dlg.input) - 2
unit = Right(dlg.input, 2)

If unit = "kb" Then
multiplier = 1024
End If

If unit = "mb" Then
multiplier = 1024^2
End If

If unit = "gb" Then
multiplier = 1024^3
End If

If unit = "tb" Then
multiplier = 1024^4
Else
multiplier = 1
stringlength = stringlength + 2
End If

output = dlg.show
size = Left(dlg.input, stringlength) * multiplier

ClickData.Func.Command.RunCommand("{alias|system}\fsutil.exe file createnew {s}{Date|yyyy-MM-dd}_{Time|HH.mm.ss}.dummy " & size)

End Function[/code]

I can't edit my previous post, so create new. After changing the script, now everything works except the modifier @runmode hide. How to use it, I do not know.

You can enter value in bytes or add unit (kb, mb, gb, tb) after it.

[code]Option Explicit

Function OnClick(ByRef ClickData)

Dim dlg
Dim input
Dim output
Dim multiplier
Dim length
Dim size
Dim unit

Set dlg = ClickData.Func.Dlg

dlg.title = "Create dummy file"
dlg.message = "Enter the file size:"
dlg.buttons = "OK|Cancel"
dlg.default = ""
dlg.Select = True
dlg.max = 15

output = dlg.show
input = Trim(dlg.input)

length = Len(input)
unit = Right(input, 2)

If StrComp("kb", unit, 1) = 0 Then
multiplier = 1024
length = length - 2
ElseIf StrComp("mb", unit, 1) = 0 Then
multiplier = 1024 ^ 2
length = length - 2
ElseIf StrComp("gb", unit, 1) = 0 Then
multiplier = 1024 ^ 3
length = length - 2
ElseIf StrComp("tb", unit, 1) = 0 Then
multiplier = 1024 ^ 4
length = length - 2
Else
multiplier = 1
End If

size = Left(Trim(input), length) * multiplier

ClickData.Func.Command.RunCommand("{alias|system}\fsutil.exe file createnew {s}{Date|yyyy-MM-dd}_{Time|HH.mm.ss}.dummy " & size)

End Function[/code]

You may be able to add @runmode hide using a multi-line command, although I haven't tried that yet from a script.

For detailed help, please link your account.

After I added the first two lines, everything worked the way I need

ClickData.Func.Command.SetType "msdos" ClickData.Func.Command.SetModifier "runmode", "hide" ClickData.Func.Command.RunCommand("{alias|system}\fsutil.exe file createnew {s}\{Date|yyyy-MM-dd}_{Time|HH.mm.ss}.dummy " & size)

Full script (workable)

Option Explicit

Function OnClick(ByRef ClickData)

Dim dlg
Dim input
Dim length
Dim multiplier
Dim output
Dim size
Dim unit

Set dlg = ClickData.Func.Dlg

dlg.title = "Create dummy file"
dlg.message = "Enter the file size:"
dlg.buttons = "OK|Cancel"
dlg.default = ""
dlg.Select = True
dlg.max = 15

output = dlg.show
input = Trim(dlg.input)

length = Len(input)
unit = Right(input, 2)

If StrComp("kb", unit, 1) = 0 Then
multiplier = 1024
length = length - 2
ElseIf StrComp("mb", unit, 1) = 0 Then
multiplier = 1024 ^ 2
length = length - 2
ElseIf StrComp("gb", unit, 1) = 0 Then
multiplier = 1024 ^ 3
length = length - 2
ElseIf StrComp("tb", unit, 1) = 0 Then
multiplier = 1024 ^ 4
length = length - 2
Else
multiplier = 1
End If

size = Left(Trim(input), length) * multiplier

ClickData.Func.Command.SetType "msdos"
ClickData.Func.Command.SetModifier "runmode", "hide"
ClickData.Func.Command.RunCommand("{alias|system}\fsutil.exe file createnew {s}\{Date|yyyy-MM-dd}_{Time|HH.mm.ss}.dummy " & size)

End Function

Full button (workable)

[code]

<?xml version="1.0"?> Dummy File... #empty Option Explicit Function OnClick(ByRef ClickData) Dim dlg Dim input Dim length Dim multiplier Dim output Dim size Dim unit Set dlg = ClickData.Func.Dlg dlg.title = "Create dummy file" dlg.message = "Enter the file size:" dlg.buttons = "OK|Cancel" dlg.default = "" dlg.Select = True dlg.max = 15 output = dlg.show input = Trim(dlg.input) length = Len(input) unit = Right(input, 2) If StrComp("kb", unit, 1) = 0 Then multiplier = 1024 length = length - 2 ElseIf StrComp("mb", unit, 1) = 0 Then multiplier = 1024 ^ 2 length = length - 2 ElseIf StrComp("gb", unit, 1) = 0 Then multiplier = 1024 ^ 3 length = length - 2 ElseIf StrComp("tb", unit, 1) = 0 Then multiplier = 1024 ^ 4 length = length - 2 Else multiplier = 1 End If size = Left(Trim(input), length) * multiplier ClickData.Func.Command.SetType "msdos" ClickData.Func.Command.SetModifier "runmode", "hide" ClickData.Func.Command.RunCommand("{alias|system}\fsutil.exe file createnew {s}\{Date|yyyy-MM-dd}_{Time|HH.mm.ss}.dummy " & size) End Function [/code]

How to use: you can enter value in bytes, kb, mb, gb or tb.
Examples:

  1. 1 byte -> type 1 and press OK
  2. 1 kb -> type 1kb (or Kb, kB, KB) and press OK
  3. 1 mb -> type 1mb (or Mb, mB, MB) and press OK
  4. 1 gb -> type 1gb (or Gb, gB, GB) and press OK
  5. 1 tb -> type 1tb (or Tb, tB, TB) and press OK

Syntax highlighting not working on ElseIf