LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   programming with directories (https://www.linuxquestions.org/questions/programming-9/programming-with-directories-306629/)

juanbobo 03-27-2005 08:32 AM

programming with directories
 
I want to write a console program to read/write the directory tree, how is it possible?

Thanks in advance,

John

acid_kewpie 03-27-2005 10:10 AM

well it's perfectly possible... nearly any programming or scripting language can do this, you just need to use it right... did you have any useful specifics???

juanbobo 03-27-2005 10:13 AM

I want to be able to do it in C++. I don't think it is possible without linking to the kernel source, but I am not sure which header files are necessary or which functions are available.

futhark 03-27-2005 10:40 AM

You don't need the kernel source to write simple C or C++ programs. You need the kernel source only when you compile programs using kernel headers and such things.

Here's a small demo.

If you're doing CPP you need g++ and cpp extensions:

cd /tmp
cat << _EOF_ > hello.cpp
#include <stdio.h>

int main (void)
{
printf( "hello world in CPP!\n" );
}
_EOF_
g++ hello.cpp -o hellocpp
./hellocpp

If you write C programs use .c extensions and gcc.

cd /tmp
cat << _EOF_ > hello.c
#include <stdio.h>

int main (void)
{
printf( "hello world in C!\n" );
}
_EOF_
g++ hello.c -o helloc
./helloc

juanbobo 03-27-2005 01:06 PM

thanks for the reply, but i am asking how to read and write the directory tree with c++. for instance, i would like to be able to display all of the directories and their contents in the file system.

futhark 03-28-2005 09:55 AM

Quote:

Originally posted by juanbobo
thanks for the reply, but i am asking how to read and write the directory tree with c++. for instance, i would like to be able to display all of the directories and their contents in the file system.
Well there were two questions:
1- is it possible to compile w/o kernel source
2- how to process file trees in cpp

I answered 1 by explaining how to compile a simple cpp prog. It it works for you too it prooves you can write your program on your system.

You'll find answer to question #2 by reading the language reference. If what you need to is not too complex, then you should learn bash scripting or similar languages (python, perl).

alred 03-28-2005 10:18 AM

Quote:

i would like to be able to display all of the directories and their contents in the file system.
this is no joke if you decided what to do next with the content of the directories

anyway you can try these C functions :
scandir, closedir, dirfd, opendir, rewinddir, seekdir, telldir , readdir

use "man 3" for quick reference then hunt for full examples on the net.

good luck

jschiwal 03-28-2005 10:28 AM

I also had a class in assembly language in college. I found it was usefull later on when I would use a debugger.

juanbobo 03-28-2005 12:24 PM

thanks alred, i was looking for the C/C++ commands to do so. i searched google for the functions you suggested and found they are available in "dirent.h" in the kernel source.

Orkie 03-28-2005 01:09 PM

I am fairly certain that they are also in glibc which would be better to compile against.


All times are GMT -5. The time now is 02:50 PM.