Output filename to VSCode replace string - visual-studio-code

Say I have a search I want to do across my entire project: callToMyFunction()
And I would like to replace it with:
callToMyFunction();
console.log("calling function from ${filename}");
Is there a way (or an extension) that could do the ${filename} (or whatever) where the filename of the file where the replacement string is being applied gets written in?
If a search match was found in the file index.js the replacement would be:
callToMyFunction();
console.log("calling function from index.js");
[BONUS if there is a way to also get line number, but I'd be more than satisfied with just the filename 😁]

Related

Filename pattern validation in adf v2

I would like to validate my input filename whether it's in specified name.
Like my filename should be <><><>_<>.csv
Yes i am using event based i will get filename from trigger.
expected format: company_contry_yearmonth_timestamp.CSV
There is no explicit regex way of validating if the incoming file name matches a pattern. But if you are using activity like lookup or copy activity. You can specify in the source dataset settings a wildcard file name or file path to fetch a file matching the pattern.
- wildcardFileName
The file name with wildcard characters under the given container and
folder path (or wildcard folder path) to filter source files. Allowed
wildcards are: * (matches zero or more characters) and ? (matches zero
or single character). Use ^ to escape if your file name has a wildcard
or this escape character inside. See more examples in Folder and file
filter examples.
example:
You can use a if condition, with an expression as below using contains()
Here a storage event trigger, gets the trigged file name into a parameter. We then use contains() function to see if the file name contains a specified string
#contains(pipeline().parameters.filenameTriggered,'pattern')
If true a wait activity is executed.

os.walk() is not throwing any error nor the result in python

I am trying to print the file names which are in a predefined paths where the paths are stored in paths.txt. But when I execute the below code, I'm not getting any error nor the files names printed.
import os
with open('D:\paths.txt', 'r') as file:
data = file.read()
path = data.split(";")
print(path)
for line in path:
for root, dirs, files in os.walk(line):
for name in files:
print(name)
You need to remove the double-quotes from the file (""). Here is why; When the file gets read by Python, after it does the .split(), the double-quote characters are part of the Python string. So instead of passing into os.walk() the path D:\bp1, you were actually passing in "D:\bp1", and there was no path that starts with a " that's why nothing was happening.
You would only need to provide the double quotes if you're writing the name in a terminal/command prompt and don't want to escape the double quotes, or if you're trying to define the string inside Python using the double quote literal, for example path = "D:\\bp1" (notice that in that case you also have to escape the \ with another one.

How to find and replace between two files using a macro in notepad++

Iv tried multiple different ways to replace text between two files using a macro but I cant get it to work. My understanding of recording macros in notepad++ is that you can only use keystrokes to perform a command and I did just that and when I played it back it doesn't replace anything.
File_1
7248683:1
9476913:467
7603090:2367
2033565:24
4730634:56789
6815648:325
2032668:57893
7930455:53
2199279:569231
8913826:6783
File_2
user:2199279
user:4730634
user:7248683
user:8913826
user:2032668
user:7930455
user:9476913
user:6815648
user:2033565
user:7603090
I'm trying to replace 7248683 in file_2 with the number right of the Colon in file_1 which would be 1 in this case, and so on throughout the entire file_2 document.
You can automate the replacements in the following way:
In a new Notepad++ document, paste in the contents of File_2, and then put the contents of File_1 in the same document beneath the contents of File_2, like this:
user:2199279
user:4730634
user:7248683
user:8913826
user:2032668
user:7930455
user:9476913
user:6815648
user:2033565
user:7603090
7248683:1
9476913:467
7603090:2367
2033565:24
4730634:56789
6815648:325
2032668:57893
7930455:53
2199279:569231
8913826:6783
Now do a regex Find-and-Replace (CHECK the box next to ". matches newline"):
Find what:
user:(\d+)(.*?^\1:(\d+))
Replace with:
user:$3$2
If there aren't a lot of replacements to make, you can just keep hitting the "Replace" button to do all the replacements. Otherwise, you can use a macro to make it repeat the replacement.
Results when performed on the example data:
user:569231
user:56789
user:1
user:6783
user:57893
user:53
user:467
user:325
user:24
user:2367
7248683:1
9476913:467
7603090:2367
2033565:24
4730634:56789
6815648:325
2032668:57893
7930455:53
2199279:569231
8913826:6783

Store user input as wildcard

I am having some trouble with a data processing function in MATLAB. The function takes the name of the file to be processed as an input, finds the desired files, and reads in the data.
However, several of the desired files are variants, such as Data_00.dat, Data.dat, or Data_1_March.dat. Within my function, I would like to search for all files containing Data and condense them into one usable file for processing.
To solve this, I would like desiredfile to be converted into a wildcard.
Here is the statement I would like to use.
selectedfiles = dir *desiredfile*.dat % Search for file names containing desiredfile
This returns all files containing the variable name desiredfile, rather than the user input.
The only solution that I can think of is writing a separate function that manually condenses all the variants into one file before my function is run, but I am trying to keep the number of files used down and would like to avoid this.
You could concatenate strings for that. Considering desiredFile as a variable.
desiredFile = input('Files: ');
selectedfiles = dir(['*' desiredfile '*.dat']) % Search for file names containing desiredfile
Enclosing strings between square brackets [string1 string2 ... stringN]concatenates them. Matlab's dir function receives a string.
I believe you can achieve that using the dir command.
dataSets = dir('/path/to/dir/containing/Data*.dat');
dataSets = {dataSets.name};
Now simply loop over them, more information here.
To quote the matlab help:
dir lists the files and folders in the MATLAB® current folder. Results appear in the order returned by the operating system.
dir name lists the files and folders that match the string name. When name is a folder, dir lists the contents of the folder. Specify name using absolute or relative path names. You can use wildcards (*).

uigetfile not pulling entire file name

I'm using uigetfile to upload my data. I've time stamped my data with a date. So a file I want to upload looks like Data-Dec01_11/45/35.txt The problem is uigetfile reads till the first "/" and then assumes that that is the end of the file name. Thus it pulls the file name Data-Dec01_11. But of course when I load that file it doesn't exist. How do I force uigetfile to pull the entire file name?
You cannot use slashes or backslashes in your file names, as they can be mistaken with the file separator, as in your case.
You can use ´regexpr´ to rename your files so they do not contain illegal characters, as explained in this trhead.
I copy here the code they suggest for your convenience (I've just added a slash and a backslash to the example string so you can see the results):
% these characters are allowed
legalchars = 'a-zA-Z0-9\-\ \_\.' ;
% illegal filename
A = 'Some#charac\ters$are(not&allowed/.txt'
% replace every other character with an underscore
B = regexprep(A,['[^' legalchars ']'],'_')