LinuxQuestions.org
Review your favorite Linux distribution.
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 10-12-2006, 10:46 AM   #1
panchosansa
LQ Newbie
 
Registered: Oct 2006
Posts: 18

Rep: Reputation: 0
ftw- can please someone explain this to me?


Hello,

I hope I would not waste your time with my question because it is a basic one and yet I don't seeem to get it. Maybe I'm just stupid . I can't understand what the ftw program is doing and for some reason I can't start it in the terminal. I looked at various descriptions and the man page but I don't get it. I even looked through its source at koders.com but still no...
Thanks and again- my apologies for the lame question.
 
Old 10-12-2006, 11:05 AM   #2
xhi
Senior Member
 
Registered: Mar 2005
Location: USA::Pennsylvania
Distribution: Slackware
Posts: 1,065

Rep: Reputation: 45
show some code, a link, a description, an error, or something that shines a light on your extremely vague statement..
 
Old 10-12-2006, 03:40 PM   #3
panchosansa
LQ Newbie
 
Registered: Oct 2006
Posts: 18

Original Poster
Rep: Reputation: 0
from ftw manpage
Quote:
ftw() walks through the directory tree starting from the indicated directory dir. For each found entry in the tree, it calls fn() with the full pathname of the entry, a pointer to the stat(2) structure for the entry and an int flag, which value will be one of the following...
I was just asking if someone could explain to me the essence of this program: what is it most commonly used for and how can I start it. Just the most trivial input/output example or whatever else that would help me understand its purpose.
 
Old 10-13-2006, 08:44 PM   #4
xhi
Senior Member
 
Registered: Mar 2005
Location: USA::Pennsylvania
Distribution: Slackware
Posts: 1,065

Rep: Reputation: 45
ok, i was not sure what you meant by program, i see now that you were referring to the ftw function..

i have never used it till now, but here is a trivial example (you asked for trivial)..

Code:
#include <stdio.h>
#include <ftw.h>

int print_path(const char* file, const struct stat* sv, int flag)
{
    printf("Found %s which is a %s\n", 
           file, (flag==FTW_F?"file":(flag==FTW_D?"directory":"not a file or directory")));
    return 0;
}

int main()
{
    ftw("/tmp/s", print_path, 0);
    return 0;
}
i just created a simple dir structure in tmp and the result of that program is this
Code:
Found /tmp/s which is a directory
Found /tmp/s/t which is a directory
Found /tmp/s/t/u which is a directory
Found /tmp/s/t/u/v which is a directory
Found /tmp/s/t/u/v/w which is a directory
Found /tmp/s/t/u/v/w/x which is a directory
Found /tmp/s/t/u/v/w/y which is a directory
Found /tmp/s/t/u/v/w/z which is a directory
Found /tmp/s/t/u/v/w/z/z_file1 which is a file
Found /tmp/s/t/u/v/w/z/z_file2 which is a file
Found /tmp/s/t/u/v/w/z/z_file3 which is a file
Found /tmp/s/t/u/v/w/z/z_file4 which is a file
which is accurate to what i created.. it seems pretty simple to use.. if you want to see the stat structure do a `man 2 stat`

hth
 
  


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
Can someone explain this to me, please? Hammett Linux - Software 3 02-16-2006 08:02 PM
Can some one please explain this to me webwolf70 SUSE / openSUSE 1 10-15-2005 02:22 AM
explain. bruse Linux - Newbie 6 09-08-2005 11:48 PM
Help me explain this please! stelmed Slackware 5 05-13-2004 04:06 AM
Can anyone explain... GoboFraggle Programming 1 02-06-2003 02:33 AM

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

All times are GMT -5. The time now is 01:52 PM.

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