LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Recursivity (https://www.linuxquestions.org/questions/linux-newbie-8/recursivity-605835/)

krs4444 12-10-2007 10:56 AM

Recursivity
 
Hello,

I need a script which lists all files in directories (recursively). The root dir will be passed as argument.
I want to compile this script with command: cc <script_filename.c> -o <filename>

Have anyone experience with that?

I appreciate all your answers!

MS3FGX 12-10-2007 11:12 AM

Well you don't compile scripts, first of all. What you are talking about it writing something in C/C++.

If you want a recursive listing of files, you can already do that on the command line without writing a program to do it. Or are you just trying to do this for your own knowledge?

terrio 12-10-2007 11:41 AM

Homework perhaps?

krs4444 12-10-2007 12:16 PM

ou, yes, of course it is not script :rolleyes: i'm sorry.

Yes, it is a part of my school project, but I want to know something about that. I can read C/C++ code, but I am newbie in Linux :study: and then I dont know how to do that.

Google found something but it compiled with errors... :mad:

Thanks for your replies ;)

jlarsen 12-10-2007 05:00 PM

Can't help you with the C part of it, but try typing the following at a command line:
du
and also
man du

matthewg42 12-10-2007 05:17 PM

It would do you a dis-service to just give you code to solve your homework problem. However thank you for being clear that it is homework. I am happy to point you in the right direction.

The function calls you need to know about to get directory listings are:
  • opendir
  • readdir
  • closedir
These are part of the standard C library. You can get detailed documentation on each by looking in section 3 of the manual. e.g. to see the documentation for opendir, open a terminal and enter the command:
Code:

man 3 opendir
You might also need to use access (which is a system call, and as such is documented in section 2 of the manual).

To build a C program, you can use the gcc program (this stands for GNU C Compiler). C++ programs are built using g++. Assuming your program code is all in one file called myprog.c, the command to compile and link is simply:
Code:

gcc -g myprog.c -o myprog
The -g includes debugging symbols in your binary which makes it possible to trace the code using gdb (the GBU DeBugger).

krs4444 12-11-2007 02:31 PM

Many many THANKS matthewg42,

I am glad of your answer and wish you the best in the future!

Once again, Thank you :)

matthewg42 12-11-2007 04:10 PM

No problem. If you have any further questions please ask. People here (me included) are reluctant to post solutions to homework questions, but so long as the questioner shows that they have tried something and ask about specific points, they will get lots of answers.

So if you have problem with a specific build error, or maybe some segment of the code does something inexplicable, post what you have done (code in [code] tags to aide readability), and you will probably get lots of helpful answers :)


All times are GMT -5. The time now is 10:33 PM.