Qhimm.com Forums

Miscellaneous Forums => Scripting and Reverse Engineering => Topic started by: Hades on 2007-03-10 18:43:11

Title: How do you work with the file system in Linux using C++?
Post by: Hades on 2007-03-10 18:43:11
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:
Title: Re: How do you work with the file system in Linux using C++?
Post by: Micky 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);
Title: Re: How do you work with the file system in Linux using C++?
Post by: Hades 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.