Intellij file template: how to set file name dynamically - templates

I'm making a intellij template MyClassController but I want to insert just MyClass as name because I need to create thousands with same pattern.
I tried
package ...
#set($BASENAME = $NAME)
#set($NAME=${BASENAME} + "Controller")
#set($OBJNAME = $BASENAME.substring(0, 1).toLowerCase() + $BASENAME.substring(1))
import ...
but if #set($NAME= ... ) is present filename popup is not showing.
BASENAME's value (that is "") became NAME's value so my file end being named "$BASENAME" or "$".
There's a way to force name popup to appear or rename file after file is generated?

Related

Get content from txt file and put it in a list Flutter/Dart

this is my first question here on stackoverflow. Before i get into the question itself, i want to point out that i'm a beginner on Flutter and Dart and have no previous experience in mobile development.
Now, as the title says i'm having some issues while trying to extract the content of a text file and store the individual names inside the indexes of a list. The end goal of my application is to print a never ending list of these names, each separated to another by a comma. For example:
top model,
torcitóre,
torcolière,
tornitóre,
tosacàni,
tossicòlogo,
tour operator,
tracciatóre,
tranvière,
trattorìsta,
trattóre²,
trebbiatóre,
trecciaiòlo,
trevière,
tributarìsta,
trinciatóre,
trivellatóre,
truccatóre,
tubìsta,
turnìsta,
The text file, named jobs.txt contains more than a 1000+ italian job names. After several hours searching, all i have here is this (got from another user):
import 'dart:async';
import 'dart:convert';
import 'dart:io';
void main(List<String> arguments) {
try {
final _jobs = File('jobs.txt');
List<String> lines = _jobs.readAsLinesSync(encoding: ascii);
for (var l in lines) print(l);
} catch (Exception) {
print(Exception.toString());
}
}
jobs.txt is inside the same directory as the dart file, which is bin.
While trying to give the _jobs variable the relative path:
FileSystemException: Cannot open file, path = 'binjobs.txt' (OS Error: Impossibile trovare il file specificato.
, errno = 2)
With absolute path:
FileSystemException: Cannot open file, path = 'C:UsersUserDesktopdartdart_application_injobs.txt' (OS Error: La sintassi del nome del file, della directory o del volume non è corretta.
, errno = 123)
For reasons i don't know, if that even matters, in the path specified in the error message, the \ look like they don't even exist.
By the way, this is my project structure:
project structure
If your solution includes the usage of the Future class or async-await keywords, i'll be thankful if you could explain me how they work.
UPDATE: Look in the comments for the full solution to this issue. The verified answer isn't the full solution.
Create an assets folder in your project, in your pubspec.yaml specify the asset (make sure it's in your assets folder, that the file exists and is readable)
flutter:
assets:
- assets/jobs.txt
Now you can access your text file like so -
import 'dart:async' show Future;
import 'package:flutter/services.dart' show rootBundle;
Future<String> loadAsset() async {
return await rootBundle.loadString('assets/jobs.txt');
}
When the function returns your text, you can split it by commas and loop through all the jobs as you wish
try using rootBundle
pubspec.yaml
assets:
- text_file/
import 'package:flutter/services.dart' show rootBundle;
Future<String> getData() async {
try {
return await rootBundle.loadString('text_file/four_words.txt');
} catch (e) {
throw (e.toString());
}
}

PowerBI: Check if the folder/directory we are loading to exists or not using Power Query

I am a newbie in PowerBi and currently working on a POC where I need to load data from a folder or directory. Before this load, I need to check if
1) the respective folder exists
2) the file under the folder is with.csv extension.
Ex. Let suppose we have a file '/MyDoc2004/myAction.csv'.
Here first we need to check if MyDoc2004 exists and then if myAction file is with.csv extension.
Is there any way we can do this using Power Query?
1. Check if the folder exists
You can apply Folder.Contents function with the absolute path of the folder, and handle the error returned when the folder does not exist with try ... otherwise ... syntax.
let
absoluteFolderPath = "C:/folder/that/may/not/exist",
folderContentsOrError = Folder.Contents(absoluteFolderPath),
alternativeResult = """" & absoluteFolderPath & """ is not a valid folder path",
result = try folderContentsOrError otherwise alternativeResult
in
result
2. Check if the file is with .csv extension
I'm not sure what output you are expecting.
Here is a way to get the content of the file by full path including ".csv", or return an alternative result if not found.
let
absoluteFilePath = "C:/the/path/myAction.csv",
fileContentsOrError = File.Contents(absoluteFilePath),
alternativeResult = """" & absoluteFilePath & """ is not a valid file path",
result = try fileContentsOrError otherwise alternativeResult
in
result
If this is not what you are looking for, please update the question with the expected output.
Hope it helps.

CLion new C++ Class file template

CLion has file template to generate C++ Class, which generates source file and header. In my project I have handler classes that have same code part, and i want to generate them by file templates. And templates that i created can't do this:
Set file names for class MyHandlerClass i want my_handler_class.cpp and .hpp
From one class name i want to generate 2 files header and source, don't know how to do that.
I also want to have string like MyClass -> my-class, found function $lowercaseAndDash($NAME) but don't know why its not works
I have template for header:
#pragma once
// includes
namespace handlers {
class ${NAME}: public Parent {
public:
// methods
};
}
I tried to solve first problem by setting the file name like this: #set ($FILE_NAME = "test_class.hpp"). But i don't know hot to set CamelCase to snake, and this don't works.
Also find in docs function to snake case, but its not works for me in file template.
Its impossible to change file name from template. When you create a C++ Class, you set class name and select file name encoding. When you create file from template its saves file with your file name. I found solution this way, enter file_name (in snake case), and with Velocity create CamelCaseName for class name:
#set( $CamelCaseName = "" )
#set( $part = "" )
#foreach($part in $NAME.split("_"))
#set( $CamelCaseName = "${CamelCaseName}$part.substring(0,1).toUpperCase()$part.substring(1).toLowerCase()" )
#end
Its impossible to generate 2 files from one click like it do C++ Class template. I have to templates, and use them both.
This function is for liveTemplates, for FileTemplate i used velocity: #set( $NeededString = $NAME.replaceAll('_', '-') )
To include header file from cpp use #[[#include]]# "${NAME}.hpp"

Give warning if folder contains more than one file type using RegExp

Using RegExp to search a folder for file types held in an Array.
How can I show a fail if the folder contains more than one different file type but it is perfectly OK to have multiple of the same file type in the folder.
Here's my code:
var AllowedFileTypes = ["orf", "tif", "tiff", "jpg", "jpeg"];
var regex = new RegExp('.+\.(?:' + AllowedFileTypes.join('|')+ ')$','i');
fileList = inputFolder.getFiles(regex);
Thanks

Excel VBA script or macro for linking to new Excel document using a template in it

I have a small family-operated shop and, in the process of speeding things up and/or automating them, I need help on the following matter (will try to explain as well as possible, since I am at a novice level on this kind of stuff.)
So, in my shop we offer a certain service (taking specific measurements of body dimensions along with weight/sugar levels etc etc). I have created an .xlsx document that contains all required fields and saved it as a template for future use. What I need to do is this:
I want to have a "master" Excel file with the names of our customers. From there, each name when clicked should open a new Excel file, using the aforementioned template, which would eventually be saved as each customer's record. I've tried a script for linking to the template but opening it as a new file (with the template in it) but, the problem is that each time I click on the name on the master file it opens a new document altogether, while I need it to open a new document named after the name in the original cell, with the template in it. As far as I can think, this is the best "automation" I can accomplish. Is it plausible? If so, how can I do it?
edit: this is the code, as i found it elsewhere:
'File:
' OfficeTemplate.vbs
'
'Problem:
' A hyperlink from an Office application to an Office template opens the template,
' instead of creating a new file.
' The proposed solution
' support.microsoft.com/kb/278627
' did not work.
'
'Solution:
' Create a hyperlink to a VBS file that starts the process.
'
'Instructions:
' Copy this VBScript into the same directory of your template.
' Rename it so that the VBS file name has the name of the template file in front.
' Example:
' Template name: test.dotx
' VBScript name: test.dotx.vbs
' Create the hyperlink to the VBS file.
Set fso = CreateObject("Scripting.FileSystemObject")
'Get the name of the template
OurName = fso.GetBaseName(WScript.ScriptName)
'Find all files in our directory
For Each File In fso.GetFolder(fso.GetParentFolderName(WScript.ScriptFullName)).Files
'Did we found the template?
If StrComp(OurName, File.Name, vbTextCompare) = 0 Then
'Invoke the default verb
CreateObject("Shell.Application").Namespace(0).ParseName(File.Path).InvokeVerb
'Wait a second to let the application start
WScript.Sleep 1000
'Done
Exit For
End If
Next
this is my template:
http://i215.photobucket.com/albums/cc55/psyclone_tread/templ.jpg
this is the master file, just a column with names and one with phone numbers, i want the names to link to each customer's individual file.
http://i215.photobucket.com/albums/cc55/psyclone_tread/master.jpg
Let me give you a very simple answer for this. Use VBA instead of VBS, and write code inside your master excel as per following illustration.
When you click on the cell with the name,
If File.Exists ("YourFolder\" & ActiveCell.Value & ".xlsx") Then
Workbooks.Open("YourFolder\" & ActiveCell.Value & ".xlsx")
Else
WorkBooks.Add(YourTemplate)
Fill in the details already present in the master sheet to new workbook if needed
NewWorkbook.Save("YourFolder\" & ActiveCell.Value & ".xlsx")
End If