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 02-24-2009, 01:09 AM   #1
busyfire
LQ Newbie
 
Registered: Feb 2009
Posts: 10

Rep: Reputation: 0
Thumbs up find command


what the find command does to recursively traverse directories and examine all the directory entries...i have to write it in c...
 
Old 02-24-2009, 01:52 AM   #2
jlinkels
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195

Rep: Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043
Implementing the full find command in C? That is big task!

Anyway, the principle is to get a directory listing, (http://www.gnu.org/software/libtool/...rectory-Lister), and descend into each directory and get a listing again by calling the same function etc. until you don't find any directory entries to descend into.

jlinkels
 
Old 02-24-2009, 02:25 AM   #3
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
Quote:
Originally Posted by busyfire View Post
what the find command does to recursively traverse directories and examine all the directory entries...i have to write it in c...
The function ftw() (ftw = file tree walk) can do most of it for you. At the bottom of "man ftw" there is a complete code example.
 
Old 02-24-2009, 09:35 AM   #4
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
Quote:
Originally Posted by Hko View Post
The function ftw() (ftw = file tree walk) can do most of it for you. At the bottom of "man ftw" there is a complete code example.
Or, you can roll your own, using opendir() + readdir() + closedir() This allows you to control whether you want to do a depth-first, or breadth-first traversal.
--- rod.
 
Old 02-25-2009, 01:12 AM   #5
busyfire
LQ Newbie
 
Registered: Feb 2009
Posts: 10

Original Poster
Rep: Reputation: 0
Thumbs up find command

Quote:
Originally Posted by Hko View Post
The function ftw() (ftw = file tree walk) can do most of it for you. At the bottom of "man ftw" there is a complete code example.
thanks man...but how we get the dirpath...how the dirpath gets the path..
 
Old 02-25-2009, 05:24 AM   #6
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
Quote:
Originally Posted by busyfire View Post
thanks man...but how we get the dirpath...how the dirpath gets the path..
Eh.. Just pass the path as a string to the ftw() function. How te get the string? That depends on the program you're making. It is for you to decide, you're the programmer...
 
  


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
Find/grep command to find matching files, print filename, then print matching content stefanlasiewski Programming 9 06-30-2016 05:30 PM
Single find command to find multiple files? thok Linux - Newbie 7 01-31-2009 04:45 PM
Using a single "Find" Command to find files bases on multiple criteria roboxooo Linux - Newbie 6 01-15-2009 04:13 AM
can't find my find command! how to replace? dave247 Debian 4 11-19-2008 10:51 AM
find command ovince Programming 1 03-09-2007 04:23 PM

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

All times are GMT -5. The time now is 08:03 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