Thank you for the reply. What I want is to do that within the code. Reason is my final code is more than this. So I am looking for away to do it within the code.
Thanks to let me know if you have any idea.
Any more replies are welcome.
This would require the minimum amount of change to your program. (you will also need fopen and fclose)
Or you could use ofstream instead.
But I'm not that well versed in the Linux way of doing thing : I do mainly Windows plus some cross-platform...
If you just want to create a file with the directory listing in it, and have no other use for the info in your program, it might be better to just get the system to run the ls command, redirecting its output to a file.
As suggested, I can not do "ls" as this code is going to be part of a bigger code that I am planning to develop. In fact, I have a program built with BASH & is working. Now that I am learning C++, I am trying to do the same with C++.
In short, I am having the below with BASH & tying to get it with C++
for ii in *.txt
do
...
...
done
Now I am facing with the requirement to take out what I needed from this file (from below - file-list.txt).
The contents of new file is as below; I lost all new line with "fputs" but I am fine if I can find a way to capture all the strings that matchs "Test_*.txt". These are file names that I want to capture into a raw so that I can search some strings in those in the directory.
If you have any idea how to capture into a new file with a "\n" at the end, I will have a new file with a all the file names that matches "Test_*.txt" so I can do my rest of the code.
I will also post this in a new topic if I could not find an answer in this.