How do you work with the file system in Linux using C++?

  • Thread starter Thread starter Hades
  • Start date Start date
Status
Not open for further replies.
H

Hades

Guest
Hi guys,

I can't believe how much trouble I am having finding the answer to these questions:

1. How to I get the location of the users home dir (or even their user name)
2. How to I check for the existence of a certain directory?
3. Which C++ library is the standard for the above tasks?


If any of you guys here can help I would be very grateful.

Thanks for reading this!  :mrgreen:
 
The problem is, that these are outside the language and more in operating system territory.
On Unix-like operating system you'd use "getenv", for example
Code: [Select]
Code:
#include <stdlib.h>char * home = getenv("HOME");
And you can use the "stat" function to get all kinds of information about a file.
Code: [Select]
Code:
#include <sys/types.h>#include <sys/stat.h>int stat(const char *path, struct stat *sb);
 
Last edited:
I thought I would share my findings here, for people who may have the same question one day.

Everything above is do-able using the glibmm library that gtkmm uses. It actually makes it quite easy.
 
Status
Not open for further replies.
Back
Top