programming with directories
I want to write a console program to read/write the directory tree, how is it possible?
Thanks in advance, John |
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???
|
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.
|
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 |
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.
|
Quote:
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). |
Quote:
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 |
I also had a class in assembly language in college. I found it was usefull later on when I would use a debugger.
|
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.
|
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. |