How to Create New/Empty Files

Hi Leo,

I would like a button to create new files (text mainly but .docx and .xlsx occasionally). I assumed that the above commands would work as a button on the current source lister. Guess I'll need to look at it a bit closer and see what I can come up with. Don't give me any tips just yet, I'll try and it figure it out. :slight_smile:

Thanks.

If you want to create them in the current source folder, the buttons earlier in the thread are what you want. The one in the 2nd post in the thread is probably what you want.

The purpose of Monkin's command (which can be done in a much better way now anyway) was to do something different to the earlier ones (create the file in the selected folder instead of the current folder).

Thanks Leo, I figured it out in the end.

To create files without extensions:

  1. Use this command:
Filetype NEW=. NEWNAME=empty
  1. Copy the code below, save it as *.reg file and run or just add apt keys/values to Windows registry yourself (if you know how to):
Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\genericfile]
@="New file (no ext)"

[HKEY_CLASSES_ROOT\.]
@="genericfile"

[HKEY_CLASSES_ROOT\.\ShellNew]
"NullFile"=""

[HKEY_CLASSES_ROOT\.\ShellNew\Config]
"NoExtension"=""

Now you can add button (see code in point 1) and assign a hotkey to it. After you create a new file with no extension, you can type extension from keyboard (filename.ext). It's much easier for me than choosing file type from a drop down list, especially that I have "always show extensions" enabled.

There's no need to mess with the registry for that, just use this as the command:

Filetype NEW=.txt NEWNAME=empty.

If the NEWNAME ends in a . then no extension will be added.

How can the text file be automatically created with the name of the currently selected file + .txt extension?

Example

Selecting "Firefox Setup 20.0.exe" and pressing the button would result in an empty plain text file titled "Firefox Setup 20.0.exe.txt" in the same directory as the original file.

Thank you.

Filetype NEW=.txt NEWNAME "{file}.txt"

Is there a way to do something like 'noselect' when creating a new file? i.e. I create a new .txt file using:

@nofilenamequoting
Filetype NEW=.txt NEWNAME="{dlgstringS|Enter new .txt file name:|New Text Document}"
@confirm:Open for editing?
notepad2 "{sourcepath}{$newfile}"

Even though I have have either manually typed in a name, or allowed the default name to happen, the file gets created, and the stem is still highlighted and selected, waiting for the rename. So, I have to either press Enter, to click an empty space to exit the rename mode, and allow for the rest of the function to finish. It'd be nice to have it not enter rename mode after the file is created.

Even a sort of hacky, Sendkeys {ENTER} type of thing would work there, but I didn't notice anything in the dox for either.

Update:
Scratch that! Solved my own problem. (norename:) :laughing:

From the FileType Command page in the manual:

3 Likes

this is what i wanted exactly
drop empty readme.txt file
cheers
FileType NEW .txt NEWNAME "norename:readme.txt"

Following the examples above, I created my own button to create an empty text file.
With three variants, using the name from the selected file, taking a name from the clipboard or a standard name.
The problem is that if I don't select any files I can't make any choices. The button don't work.
Is it possible to hide a choice if it doesn't meet the requirements? (i.e. if I do not select anything or there is no text in the clipboard)

Maybe you have some suggestions!
Thank you

@nofilenamequoting
@set tempname= {dlgchoose|Nome del File:|Selezione={file$|noext}+Clipboard={clip}+Nuovo Documento=Nuovo documento}
@set name {dlgstringS|Nome del File:|{$tempname}}
Filetype NEW=.txt NEWNAME="norename:{$name}"
EditPadPro8 "{sourcepath}{$newfile}"

Yes, but you would need to use scripting for that kind of conditional logic.

Use file instead of file$.

Same thing, if I change that and don't select the file, the button doesn't work ..

Actually I created a small dialog for creating a set of predefined filetypes (emtpy files with specific extensions). I use jscript for accomplishing this. If interested i can share this code.

With scripts I don't even know where to start, but if you can share it, I try to see if I can adapt it to my needs .

If you're running this from a toolbar button, the easiest thing to do would be to change the button into a menu, then put the individual commands you want as items within that. Doesn't require any script or dialogs at all then.

(Downside: It wouldn't tell you what was currently in the clipboard as part of the labels.)

Effectively, better than nothing...

Here is my button. Very old, might not be a good implementation but might help you.
image
New file.dcf (6.6 KB)
(Just updated the button, there was a small bug in it).

And this might be the interesting code snippet for you.

function CreateFile(path, fileName)
{
	var fso = new ActiveXObject("Scripting.FilesystemObject");
	var file = fso.CreateTextFile(path +"\\" + fileName, true);
	file.Close();
}

3 Likes

Thanks, I'll do some tests