LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-27-2005, 08:32 AM   #1
juanbobo
Member
 
Registered: Mar 2005
Location: Chicago
Distribution: Gentoo AMD64
Posts: 365

Rep: Reputation: 30
programming with directories


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

Thanks in advance,

John
 
Old 03-27-2005, 10:10 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
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???
 
Old 03-27-2005, 10:13 AM   #3
juanbobo
Member
 
Registered: Mar 2005
Location: Chicago
Distribution: Gentoo AMD64
Posts: 365

Original Poster
Rep: Reputation: 30
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.
 
Old 03-27-2005, 10:40 AM   #4
futhark
Member
 
Registered: Nov 2003
Location: Montréal (Can)
Distribution: FC4
Posts: 110

Rep: Reputation: 15
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

Last edited by futhark; 03-27-2005 at 10:42 AM.
 
Old 03-27-2005, 01:06 PM   #5
juanbobo
Member
 
Registered: Mar 2005
Location: Chicago
Distribution: Gentoo AMD64
Posts: 365

Original Poster
Rep: Reputation: 30
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.
 
Old 03-28-2005, 09:55 AM   #6
futhark
Member
 
Registered: Nov 2003
Location: Montréal (Can)
Distribution: FC4
Posts: 110

Rep: Reputation: 15
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).
 
Old 03-28-2005, 10:18 AM   #7
alred
Member
 
Registered: Mar 2005
Location: singapore
Distribution: puppy and Ubuntu and ... erh ... redhat(sort of) :( ... + the venerable bsd and solaris ^_^
Posts: 658
Blog Entries: 8

Rep: Reputation: 31
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

Last edited by alred; 03-28-2005 at 02:02 PM.
 
Old 03-28-2005, 10:28 AM   #8
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
I also had a class in assembly language in college. I found it was usefull later on when I would use a debugger.
 
Old 03-28-2005, 12:24 PM   #9
juanbobo
Member
 
Registered: Mar 2005
Location: Chicago
Distribution: Gentoo AMD64
Posts: 365

Original Poster
Rep: Reputation: 30
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.
 
Old 03-28-2005, 01:09 PM   #10
Orkie
Member
 
Registered: Mar 2005
Distribution: Breezy Badger
Posts: 248

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


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
which programming language is used to do tcp/ip programming?? gajaykrishnan Linux - Networking 9 12-21-2012 05:16 AM
CHMOD directories.sub-directories.files zerojosh Linux - Software 2 11-19-2005 03:22 PM
Searching multiple directories and sub directories for a file jeep99899 Linux - Newbie 2 10-13-2005 12:23 PM
Difference between Top Down programming & Bottom up programming minil Programming 1 06-17-2005 02:42 AM
Directories? Dev930 Linux - Newbie 3 02-28-2004 06:34 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:08 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration