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.
Related
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.
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:
How can I make Notepad to save text in UTF-8 without the BOM?
(7 answers)
Closed 5 years ago.
I want to read in a .txt file using ifstream fin from library fstream, but there is a BOM at the beginning of the file that is causing problems. Is there a way I can, from inside my C++ program, eliminate the BOM in the .txt file, so that fin can read it without any issues? I know I can manually delete the BOM in the file myself, but I have multiple files I'm working with so this will take a while.
My question is similar to this one here, except this one deals in Java:
How to make Notepad to save text in UTF-8 without BOM?
The answer from korifey is what I am looking for, where they said:
Use PushbackInputStream(in, 3)
Is there something similar I can do in C++ ? It should also be noted that I only have Notepad (not Notepad++), and it is preferable to solve my problem without downloading any new software. I also don't want to change how Notepad itself views BOMs, I just want to physically delete the BOM from my .txt file. The BOM I'm dealing with is the first 8 characters.
This would be easiest by opening the file in binary mode, reading all the data and copying everything but the BOM to a different file, then removing the old file and finally renaming the new file back to the name of the old.
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
This question already has an answer here:
Why do I have to use double backslashes for file-paths in code?
(1 answer)
Closed 8 years ago.
I have the following folder structure:
/code
/files
(i.e "files" folder is present inside the "code" folder)
I am trying to create a file(and write in it) using of fstream like this:
ofstream out("\files\plsmap.txt");
The compiler isn't giving any error, but, no file is being created in the "files" folder. What can be the possible reason for this and also, is there some other way of doing this
You wrote "\files\plsmap.txt". The leading slash specifies the root directory of your entire file system. So "\files" is very different from "\code\files". You could try removing the leading slash, or changing the string so that it contains the full, absolute path to the directory you are trying to write. You can figure out the absolute path of a directory by running pwd in that directory from a terminal.
Besides the misplaced slashes, the other thing to note is that backslashes are special inside C++ strings, and they need to be escaped using a second backslash when you are writing them in your C++ source code:
const char * path = "code\\plsmap.txt";
Your environment might allow you to use forward slashes instead, which would be easier since they don't need to be escaped.