LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
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
 
LinkBack Search this Thread
Old 11-20-2009, 04:56 AM   #1
weeshalll
LQ Newbie
 
Registered: Nov 2009
Posts: 11

Rep: Reputation: 0
Using the "readdir" command


Hello all .
I have a code which reads all the files from in directory in a loop using the "readdir" command.At the end of the loop i want to print a message saying "All the files have been read".
I want to know whether the command returns any specific error code when all the files have been read.

Thanks in advance
 
Old 11-20-2009, 05:20 AM   #2
centosboy
Senior Member
 
Registered: May 2009
Location: london
Distribution: centos5
Posts: 1,137

Rep: Reputation: 115Reputation: 115
Quote:
Originally Posted by weeshalll View Post
Hello all .
I have a code which reads all the files from in directory in a loop using the "readdir" command.At the end of the loop i want to print a message saying "All the files have been read".
I want to know whether the command returns any specific error code when all the files have been read.

Thanks in advance
if a file has been read in, an exit code of 0 is returned for each file read in. as it is a loop, im afraid a 0 for each line.

of course you can set a condition for the whole script.

Last edited by centosboy; 11-20-2009 at 05:22 AM.
 
Old 11-20-2009, 06:39 AM   #3
weeshalll
LQ Newbie
 
Registered: Nov 2009
Posts: 11

Original Poster
Rep: Reputation: 0
But i want to know what error code would be returned when all the files are
read from that directory ?
 
Old 11-20-2009, 06:52 AM   #4
centosboy
Senior Member
 
Registered: May 2009
Location: london
Distribution: centos5
Posts: 1,137

Rep: Reputation: 115Reputation: 115
Quote:
Originally Posted by weeshalll View Post
But i want to know what error code would be returned when all the files are
read from that directory ?
if this section of the code runs successfully, then 0
 
Old 11-20-2009, 06:58 AM   #5
weeshalll
LQ Newbie
 
Registered: Nov 2009
Posts: 11

Original Poster
Rep: Reputation: 0
Ohhh .....
Thanks for the reply....
So u mean to say there would be no specific error code to tell me that
all the files in the directory have been read .
 
Old 11-20-2009, 07:06 AM   #6
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: FreeBSD, Puppy
Posts: 3,016

Rep: Reputation: 91
read the manual page.

man readdir

Code:
     The readdir() function returns a pointer to the next directory entry.  It
     returns NULL upon reaching the end of the directory or detecting an
     invalid seekdir() operation.


     The readdir_r() function provides the same functionality as readdir(),
     but the caller must provide a directory entry buffer to store the results
     in.  If the read succeeds, result is pointed at the entry; upon reaching
     the end of the directory result is set to NULL.  The readdir_r() function
     returns 0 on success or an error number to indicate failure.
 
Old 11-20-2009, 07:18 AM   #7
weeshalll
LQ Newbie
 
Registered: Nov 2009
Posts: 11

Original Poster
Rep: Reputation: 0
Thanks a lot !!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
readdir() gives "." and ".." and doesn't exclude some folders Tordne Programming 12 08-13-2009 04:01 PM
ns:"error when calling class OldSim"&tclsh:"invalid command+child process exits abn." shojaru Linux - Newbie 0 03-06-2009 01:44 PM
Command "mail" returns "panic: temporary file seek" kenneho Linux - Software 5 12-23-2008 04:27 AM
Standard commands give "-bash: open: command not found" even in "su -" and "su root" mibo12 Linux - General 4 11-11-2007 11:18 PM
some problem about use "readdir" PLEASE HELP ME wilson-china Programming 1 03-11-2004 02:38 AM


All times are GMT -5. The time now is 07:14 AM.

Main Menu
 
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
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration