This question already has answers here:
Removing extension of a file name in Qt
(5 answers)
Closed 3 years ago.
I want to save some files with QT:
QString path = SAVE_AUDIO_PATH+filename+QDateTime::currentDateTime().toString("yyyyMMdd_hhmmss");
filename have a format audiotest.txt
I want to delete a ending of filename - change from audiotest.txt -> audiotest
How can I do it? Thank you!
The right way to get rid of the file extension is using QFileInfo class. For example:
auto fileNameWithoutExtension = QFileInfo(fileName).baseName();
If you can safely assume there is always an extension, you can use:
filename.left( filename.lastIndexOf( '.' ) )
Otherwise, you would have to check to see if it has an extension or not first.
Related
This question already has answers here:
How to put a static text (postfix, prefix) in QLineEdit?
(2 answers)
Closed 2 years ago.
It's possible to set a fix string at first of QLineEdit? something like this:
Which in here $ is constant and user could not remove or edit it.
use the input mask in the object: e.g.
ui->lineEdit->setInputMask("$ 000.000.000.000 ");
will look like
This question already has answers here:
How to edit all lines in Visual Studio Code
(9 answers)
Closed 3 years ago.
So essentially someone on our dev team made a bit of a big issue where they had changed all of the build actions on .csproj files and we are thinking of the easiest way to change them back.
We want to use regex to open all the csproj files via VSCode. The format to open multiple files in file explorer is
"filename" "filename1" "filename2"
my list is
com.Console.job1.csproj
com.Console.job2.csproj
com.Console.job3.csproj
com.Console.job4.csproj
my current regex
(.+)\n
then my regex to replace is
"$1"\s
which doesnt work at all
You can use this regex :
To locate pattern
([^\s]+)(\n)?
To replace :
"$1"
keep in mind the replace pattern contains a space at its end
Demo :
Here
This question already has answers here:
What special characters must be escaped in regular expressions?
(13 answers)
Closed 5 years ago.
I 've a File structure "solution/"
Need a reg exp to match all the files under "solution/" Excluding .img files in the path "solution/tree/changes/sample.img"
I tried below it but of not worked
^solution\/tree\/changes\/((?!.img).)*$
Thanks in advance
You did not mention language, but this should work
^solution\/tree\/changes\/(?!.*\.img).*$
see regex101 demo: https://regex101.com/r/Y7znBy/1
Important! You need to set multilineflag
#Fallenhero My Exact requirement is I 've following file structure
solution/moon/
solution/tree/anomoly/
solution/tree/enquiry/
solution/tree/changes/space.img
solution/tree/changes/mine.txt
I've to parse a json file as input with regular expression to copy all the files in the above structure except solution/tree/changes/space.img
JSON Input which I've tried but didn't work
"^solution\/(?!tree\/).*\/*",
"^solution\/tree\/(?!changes\/).*\/*",
"^solution\/tree\/changes\/((?!.img).)*$"
Could you please provide your ideas
This question already has answers here:
How to open a folder in %appdata% with C++?
(6 answers)
Closed 6 years ago.
I need help creating a Folder in AppData.
Lets say I want to create a Folder in %appdata% called "MyFolder", which has the text file test.txt
I tried to use <fstream> and do this;
ofstream file("%appdata%\MyFolder\test.txt");
but it didn't work..
Things like %appdata% are OS specific, and Standard C++ has no direct means of dealing with them. You will have to write code to parse the file path, and extract values like %appdata% from the environment, or alternatively use non-standard functions to open the file, should such exist.
P.S. It also wouldn't work because "\" escapes the quotes, do "\\" instead.
This question already has answers here:
Batch rename files
(9 answers)
Closed 7 years ago.
I want to rename name of files test123..-1.in, test123..-2.in, etc. to test123.in.
I tried commands:
rename -/d.in .in *.in, and many of similar but no one works(Can You explain why?).
Then i tried rename 's/.[0-9]*.in$/.in/' *.in, with same result..
Any proposition how to solve this problem in the simple way? I dont wanna write it mannualy.
Thanks for Your help.
You can use this rename:
rename 's/\.+-\d+\././' test123..-*in
or as per OP's comment below:
rename 's/-\d+\.in/.in/' *.in