Script to create a text file with same name as an existing file

Greetings Dopus Fraternity
Is this a feasible spec for ascript?

With a file highlighted
Invoke the script
Script copies the name of the file (no extension)
Creates a text file with same name in the same folder
Opens the text file
Script ends

This post suggests that I might get quite far using internal command..but maybe not far enough?

any thoughts or suggestions greatly appreciated as always.

This button should do the trick. Script code is..

function OnClick(clickData)
{
	var cmd = clickData.func.command;
	cmd.deselect = false; // Prevent automatic deselection
	var src = clickData.func.sourcetab;
	if (src.selected_files.count==0) return; // No files are selected
	var txt_filespec = src.selected_files(0).path + "\\" + src.selected_files(0).name_stem + ".txt";
	if (DOpus.FSUtil.Exists(txt_filespec)==false){ // Don't interfere with an existing text file
		var fso = new ActiveXObject("Scripting.FileSystemObject");
		var ForWriting = 2;
		var txt_fil = fso.OpenTextFile(txt_filespec,ForWriting,true);
		txt_fil.close();
	}
	cmd.RunCommand("Notepad " + txt_filespec);
}

MakeText.dcf (1.4 KB)

1 Like

Wonderful! thank you sir.
Will try it now...

@aussieboykie thank you so much it works a treat.
I had some trouble (Like it has to JScript not VB - doh!)
Work perfectly and I have a basis to edit, extend and learn as I go.
Saved me many many hours.
Thank you sir.
Brisbane Boy

Yes:

@sync 
FileType NEW .txt NEWNAME "norename:{file|ext=txt}"
Notepad {$newfile}

Or let Notepad create the file(s):

Notepad {file|ext=txt}
1 Like

@lxp works perfectly.
Amazing.
Thank you

For the second option it's actually better to use {filepath|ext=txt} to avoid being at Notepad's mercy where the file will be saved.