Questions tagged [readdir]

The C, Perl or PHP library function for reading from an open directory.

The readdir C library function reads and returns the next entry, as a struct dirent *, from an open DIR *. You should open the directory using opendir first. This can also refer to the Perl or PHP functions with the same purpose.

Links:

301 questions
388
votes
46 answers

Node.js fs.readdir recursive directory search

Any ideas on an async directory search using fs.readdir? I realize that we could introduce recursion and call the read directory function with the next directory to read, but I'm a little worried about it not being async... Any ideas? I've looked at…
crawf
  • 9,448
  • 10
  • 33
  • 43
64
votes
10 answers

What reasons are there to prefer glob over readdir (or vice-versa) in Perl?

This question is a spin-off from this one. Some history: when I first learned Perl, I pretty much always used glob rather than opendir + readdir because I found it easier. Then later various posts and readings suggested that glob was bad, and so now…
Telemachus
  • 19,459
  • 7
  • 57
  • 79
63
votes
7 answers

Does readdir() guarantee an order?

I'm getting a list of files on a linux-like system using opendir/readdir. It appears that the directory entries are returned in alphabetical order of file name. However, I don't see anything in the man pages about this order being guaranteed. Can…
Tom
  • 18,685
  • 15
  • 71
  • 81
30
votes
3 answers

Members of Dirent structure

I have started working with dirent.h library and I came across a very useful member of "struct dirent" structer which struct dirent *p->d_name in my book. But unfortunatly it doesn't states any other members of this structure; I was wondering what…
Naruto
  • 1,710
  • 7
  • 28
  • 39
29
votes
2 answers

fs.readdir ignore directories

I would like to scan the folder, but ignore all the folders/directories that are included in it. All I have in the (C:/folder/) are .txt files and other folders, I just want to scan the txt files, and ignore the folders. app.get('/generatE',…
Tony
  • 474
  • 1
  • 7
  • 19
28
votes
2 answers

php recursive folder readdir vs find performance

i came across few articles about performance and readdir here is the php script: function getDirectory( $path = '.', $level = 0 ) { $ignore = array( 'cgi-bin', '.', '..' ); $dh = @opendir( $path ); while( false !== ( $file = readdir(…
rcs20
  • 595
  • 9
  • 27
21
votes
7 answers

How can I list all files in a directory sorted alphabetically using PHP?

I'm using the following PHP code to list all files and folders under the current directory:
David B
  • 29,258
  • 50
  • 133
  • 186
19
votes
5 answers

Efficiently Traverse Directory Tree with opendir(), readdir() and closedir()

The C routines opendir(), readdir() and closedir() provide a way for me to traverse a directory structure. However, each dirent structure returned by readdir() does not seem to provide a useful way for me to obtain the set of pointers to DIR that I…
14
votes
2 answers

How to use S_ISREG() and S_ISDIR() POSIX Macros?

This is a C program I wrote to recursively navigate and output directories and regular files. It compiles and runs fine on my Linux machine. But on Solaris, the dit->d_type == 8 check and the other similar ones don't work because there is no d_type…
Zach Alberico
  • 268
  • 3
  • 6
  • 19
13
votes
4 answers

Checking if a dir. entry returned by readdir is a directory, link or file. dent->d_type isn't showing the type

I am making a program which is run in a Linux shell, and accepts an argument (a directory), and displays all the files in the directory, along with their type. Output should be like this: << ./Program testDirectory Dir directory1 lnk…
Barney Chambers
  • 2,720
  • 6
  • 42
  • 78
10
votes
6 answers

Filter filenames by pattern

I need to search for files in a directory that begin with a particular pattern, say "abc". I also need to eliminate all the files in the result that end with ".xh". I am not sure how to go about doing it in Perl. I have something like…
Bi.
  • 1,846
  • 8
  • 25
  • 34
9
votes
3 answers

How can I read the files in a directory in sorted order?

When I read a directory in Perl with opendir, readdir, and closedir, the readdir function doesn't seem to read the files in any specific order (that I can tell). I am reading a directory that has subdirectories named by epoch…
BrianH
  • 7,932
  • 10
  • 50
  • 71
9
votes
2 answers

readdir() beginning with dots instead of files

I have a little problem. I'm reading files from directory and it works, but it read two extra files on the beginning ...what is it? for example, there is a list of files: "A348", "A348A", "A348B" and this is what i get: ".", "..", "A348", "A348A",…
user3036674
  • 143
  • 2
  • 3
  • 7
8
votes
4 answers

Perl readdir in order

Is there any way to guarantee an order from the list returned by readdir? I have the code: opendir(my $DIR, $src) or die "Error opening $src"; # Loop for each file in the directory while (my $file = readdir($DIR)) { print "$file\n"; …
Travv92
  • 791
  • 4
  • 14
  • 27
7
votes
3 answers

php read directory sorting

i have a little php script that reads a directory and then echos all the files (jpg's in this case) into a jquery image slider. it works perfectly, but i dont know how to sort the images by name desending. at the moment the images are random.…
Piet Bez
  • 95
  • 1
  • 2
  • 7
1
2 3
20 21