Can anyone help ? No filename + open it

Hi,

I created a new rightclick context item called "New file + open it !".

@nofilenamequoting @set fn={dlgstringS|Enter new file name (extension will be .txt)|New Textfile} FileType NEW=.txt NEWNAME="norename:{$fn}" Select PATTERN="{$fn}" DESELECTNOMATCH "C:\Program Files\Notepad++\notepad++.exe" "{$fn}"

Whenever I use this option and I enter the name like this : textfile.nfo
a file is created called textfile.nfo and notepad++ correctly opens the file.

Unfortunatelly, whenever I enter a name without an extension, the functions add the default .txt extension, so when I just enter textfile
a file is created called textfile.txt
but then notepad++ errors out that it cannot find the file textfile (note: no extension)

So my question is, is it somehow possible to call a conditional so when ONLY no extension is entered, the {$fn} value get the string ".txt" added, and notepad++ gets the correct filename to open ?

TIA!

The Filetype NEW command automatically sets a variable called newfile with the name of the newly created file, so you could do something like this:

@nofilenamequoting @set fn={dlgstringS|Enter new file name (extension will be .txt)|New Textfile} FileType NEW=.txt NEWNAME="norename:{$fn}" Select PATTERN="{$newfile}" DESELECTNOMATCH "C:\Program Files\Notepad++\notepad++.exe" "{$newfile}"

Perfect ! Thanks jon ! :slight_smile:

This method of creating/opening a new file works great for me for certain file types. I made a couple of different buttons depending on what type of new file i want to create. I made one for SAS files and it works fine. When i try to use a different file type (e.g., ".r") i dont get a response. This occurs even if i have .r included in the "system file types" (settings..file types).

i take it there is a step i'm missing?

Does .r appear in the New menu that you get when you right-click the folder background? (Hold Shift while right-clicking if you don't see the New menu due to having Windows menu items hidden.)

If the .r type isn't in the New menu then the FileType NEW=.r command will not work.

You might be able to create an empty file with the .r extension but that depends on the .r file format and whether programs which work with it understand that empty is new. Some file formats (e.g. Zip) require headers and other data even in "empty" files.

Nope, there isnt an item for R in the New menu that you get when you right-click the folder background

Can I add one?

These will just be plain text files that I edit with a text editor (WinEdt)

You could add an item for .r to the New menu but it requires messing around with the Registry (or TweakUI).

Since it just needs an empty file you can do it more easily:

@set name={dlgstringS|Enter File Name|New File}.r Copy FILE="nul" AS="{$name}" HERE "C:\Program Files\WinEdit\WinEdit.exe" "{$name}"

Or something like that.

If WinEdit is like many text editors then it will create new files automatically if the specified name doesn't exist, in which case you can just use this:

"C:\Program Files\WinEdit\WinEdit.exe" "{dlgstringS|Enter File Name|New File}.r"

Both cases assume that's the right path to WinEdit.exe.

If you don't want the .r extension to be automatic then you can move it inside the user-supplied name string:

... "{dlgstringS|Enter File Name|New file.r}"

That will prompt you with "New file.r" being the default name which you can type over. The first two examples would prompt you with "new file" and let you type over that, adding .r to the end implicitly.

The second approach didnt work, but the first worked great. Thanks a bunch! This is what I used:@set name=DALREV_PGM_{dlgstringS|Enter File Name|New File}.r Copy FILE="nul" AS="{$name}" HERE "C:\Program Files\WinEdt Team\WinEdt\WinEdt.exe" -C="WinEdt/PGM" -E="C:\Program Files\WinEdt Team\WinEdt\WinEdt-PGM.ini" "{$name}" Thanks again!