Skip to contentSkip to conversation

Directory contents

DISCUSSION HIToC 6 participants 6 messages Nov 27, 2004 – Nov 29, 2004

lore
Share & tools
lore

HIToC

author
#0 lore raw

Hi all!

I want to write a function that can read the contents of a specified directory in order to find a certain type of file or to copy a directory-tree or something else.
Neverthless I need of some system functions that find the files that are contained in that directory (like FINDFIRST and FINDNEXT under ms-dos).

Who can help me?

Signature · 3 lines
With regards,
				HIToC 
				[email protected]
#1 lore raw

HIToC wrote:
...

Quoted 5 lines

I want to write a function that can read the contents of a specified directory in order to find a certain type of file or to copy a directory-tree or something else.
Neverthless I need of some system functions that find the files that are contained in that directory (like FINDFIRST and FINDNEXT under ms-dos).

opendir( ) and readdir( ) might be what you are looking for?

#2 lore raw
In reply to HIToC

opendir, readdir, closedir are C standard library calls.

Quoted 12 lines · HIToC

Hi all!

I want to write a function that can read the contents of a specified directory in order to find a certain type of file or to copy a directory-tree or something else.
Neverthless I need of some system functions that find the files that are contained in that directory (like FINDFIRST and FINDNEXT under ms-dos).

Who can help me?

#3 lore raw
Quoted 1 line

opendir, readdir, closedir are C standard library calls.

Actually they are POSIX standard library calls. The C standard does not cover anything involving directories.

b

#4 lore raw
In reply to HIToC
Quoted 7 lines

I want to write a function that can read the contents of a specified directory in order to find a certain type of file or to copy a directory-tree or something else.
Neverthless I need of some system functions that find the files that are contained in that directory (like FINDFIRST and FINDNEXT under ms-dos).

Who can help me?

"man scandir" and man on functions mentioned at the end of that manpage.

--
regards
sandeep
--------------------------------------------------------------------------
You probably wouldn't worry about what people think of you if you could know how seldom they do.
-- Olin Miller.
--------------------------------------------------------------------------

#5 lore raw

On Mon, 2004-11-29 12:55:17 +0530, sandeep <[email protected]> wrote in message <[email protected]>:

Quoted 9 lines
Quoted 8 lines

I want to write a function that can read the contents of a specified directory
in order to find a certain type of file or to copy a directory-tree or something else.
Neverthless I need of some system functions that find the files that are contained in that directory (like FINDFIRST and FINDNEXT under ms-dos).

Who can help me?

"man scandir" and man on functions mentioned at the end of that manpage.

From the man page:
----------------------------- >8 ====================================== CONFORMING TO
None of these functions is in POSIX. LSB has deprecated the library call alphasort() and never contained scandir().

The functions scandir() and alphasort() are from BSD 4.3, and have been available under Linux since libc4. Libc4 and libc5 use the more pre- cise prototype

int alphasort(const struct dirent **a, const struct dirent **b);

but glibc 2.0 returns to the imprecise BSD prototype.

The function versionsort() is a GNU extension, available since glibc
2.1. Since glibc 2.1, alphasort() calls strcoll(3); earlier it used
strcmp(3).
============================================ 8< -----------------------

So I guess you don't really want to use these functions. opendir(), readdir() and closedir() are what's ment for that. If you're actually writing an libc replacement (and thus need to use the syscall interface instead of the libc interface), you can use open(..., ... | O_DIRECTORY) in conjunction with getdents().

MfG, JBG

Signature · 4 lines
Jan-Benedict Glaw       [email protected]    . +49-172-7608481             _ O _
"Eine Freie Meinung in  einem Freien Kopf    | Gegen Zensur | Gegen Krieg  _ _ O
 fuer einen Freien Staat voll Freier Bürger" | im Internet! |   im Irak!   O O O
ret = do_actions((curr | FREE_SPEECH) & ~(NEW_COPYRIGHT_LAW | DRM | TCPA));