c++: how to read from and write to a folder - c++

I've found tons of examples on file IO, but nothing with folders?
anyone have a quick example?
Note: I'm on *.nix

You can take a look at Boost FileSystem

You shouldn't be reading and writing to folders - that's the file system's job. If you want to read a directory, take a look at opendir and friends.

Take a look at opendir, readdir, closedir, etc. functions.

Related

Getting specfic files in C++ code from *nix system

I want to get all the files of type A*.txt present in current directory via C++ code. My OS is *Nix system. Also, I want to get the names of such files.
Please suggest how can this be done.
I tried using system command but system doesn't return anything apart a integer which says if command was executed properly or not.
Thanks
There are basically three ways you can go about this.
One is to use basically what you tried before, but using the popen function, which allows you to read the output of the command(s) you run.
The second solution is to use e.g. opendir and readdir or scandir to manually filter and find the files you look for.
The third and easiest way is to use the glob function.
There is actually a fourth way as well, one which is platform independent and more C++-ish than the above methods: Using the Boost filesystem library.

Reading several images from sub folders.. C++/opencv

I would like to know how to implement a code to read images in folders, for example; I have a folder with name "images" and this folder has sub folders which every sub folder contains many images. I want to read all these images by using c++/opencv in order to use these images to extract features from them all.
You should use a folder and file enumeration API.
Some portable APIs include Boost Filesystem and STLSoft.
This is unrelated to OpenCV.
On Linux, you use the opendir, readdir and closedir functions. See http://pubs.opengroup.org/onlinepubs/007908799/xsh/readdir.html. You need to do this recursively to walk the directory tree.
The simplest way might be for you to use nftw. It will do all the directory traversal for you (with options to control how) and execute your callback function. There is a small code example on the man page.
You can also use filesystem of boost to iterate through folders for reading. Use back_iterator.

C++ wrapper code to extract .zip file?

I want to unzip the .zip file.
can anyone suggest me good C++ wrapper for it ?
QuaZIP - Qt/C++ wrapper for ZIP/UNZIP package
Can't go wrong with zipios++
For Qt/Embedded I have used libzip which works on all platforms.
There are also several answers on this other SO question worth looking at:
https://stackoverflow.com/questions/4518129/qt-classes-to-zip-unzip-files
I haven't used any yet, but have looked carefully at the docs of several, and for handling entire archives of multiple files, it looks like OSDaB provides the easiest solution.

C++, console Application, reading files from directory

I have a directory and I want to read all the text files in it using C++ and having windows OS also using console application
I don't know the files' names or their number
thanks in advance
Take a look at Boost.Filesystem, especially the basic_directory_iterator.
If you want the C++ and portable way, follow the solution by #Space_C0wb0y and use boost.Filesystem, otherwise, if you want to get your hands dirty with the Windows APIs, you can use the FindFirstFile/FindNextFile/FindClose functions.
You can find here an example related to them.

how to read a list of current running process in linux using C++

i need to read the list of current running process into a C++ program.
I know that one way to do is to use ps command and other is to read /proc file system but i want to know how one can get names of processes by reading /proc file system.
also is there any other way to read the list.
There is no other way to read the list, /proc exists for this purpose. The simplest way to find out exactly how to do this job would be to read the source for procps, which may include a library to do most of the work for you.
you might want to try out libstatgrab, it should be able to give you unified access to that information on many different operating systems. It will still open /proc on GNU/Linux, but you won't know.
You can read all information from /proc/<process pid>/. I guess the file cmdline and the link exe in each of these directories will be relevant for you.