File Name Template

Is it possible to create file name templates? A simple use case would be prepending a date to a file name, e.g., 20180223-SomeFile.txt.

 

Thanks in advance!

1
2 comments

I was able to achieve something similar to what you ask by hacking around, using this as the default file name for a c# file template :

$NAME$AppendedText.cs

Then when creating the file, ensure you give only the name you would like :

input : SomeName

file created : SomeNameAppendedText.cs

I got the variable name from intellij documentation :
File template variables | IntelliJ IDEA Documentation (jetbrains.com)

Maybe some of the listed variable there works as well..

0

Hello Edward,

Thank you for contacting Rider support.
Regrettably, there is no built-in way for that. 

However, there is a way to implement such a "feature" using Run Configuration that invokes your own script.

Consider you have an executable (or .dll) that invokes the following code:

public static void Main(string [] args)
// [0] - Path to folder [1] - Postfix (File name)
{
StringBuilder fullPathBuilder = new StringBuilder();
fullPathBuilder.Append(args[0]);
fullPathBuilder.Append(DateTime.Today.ToString("d").Replace("/", "."));
fullPathBuilder.Append("_");
if (args.Length < 2)
{
Console.WriteLine("Write file name end and extension");
String fn = Console.ReadLine();
fullPathBuilder.Append(fn);
}
else
fullPathBuilder.Append(args[1]);

try
{
File.Create(fullPathBuilder.ToString());
Console.WriteLine("File created: " + fullPathBuilder.ToString());
}
catch (Exception ex)
{
Console.WriteLine("Error while creating a file. No file created");
}
}

When you built such a program and have its executable, you can open your main solution and create a run configuration as below:

Now you can launch this configuration from ToolBar:

Depending on your implementation, you would get appropriate behavior:

Hope that helps.

Should you have any other questions or difficulties, please let me know.

Have a nice day!

0

Please sign in to leave a comment.