Author Topic: How do you work with the file system in Linux using C++?  (Read 2714 times)

Hades

  • *
  • Posts: 43
    • View Profile
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:

Micky

  • *
  • Posts: 300
    • View Profile
Re: How do you work with the file system in Linux using C++?
« Reply #1 on: 2007-03-10 20:42:29 »
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]
#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]
#include <sys/types.h>
#include <sys/stat.h>

int stat(const char *path, struct stat *sb);
« Last Edit: 2007-03-10 20:44:29 by Micky »

Hades

  • *
  • Posts: 43
    • View Profile
Re: How do you work with the file system in Linux using C++?
« Reply #2 on: 2007-04-08 11:01:30 »
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.