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
1
vote
2 answers

readdir returning empty array on second call

When I open a directory with opendir() and later call readdir() two times in a row, the latter returns an empty array. minimal_example.pl: #!/usr/bin/perl use strict; use warnings; use Data::Dumper qw(Dumper); opendir(my $DIRH, "/home") or die…
noah
  • 312
  • 2
  • 13
1
vote
1 answer

Glob and counter in php

I have this script which arranges my folders in some tags and takes only 4 items.. which is great! But I need it to take the items by the alphabet $counter = 0; $directory = opendir("albums/"); while (($item = readdir($directory)) !== false &&…
Elad
  • 75
  • 2
  • 10
1
vote
0 answers

mapping files using readdirsync with es6 modules

In my Node project I'm using es6 imports instead of commonjs' require(). I've found this snippet to map through a folder and insert the files as the second argument to app.use(): readdirSync('./routes').map(r => app.use('/', require('./routes/'…
AndyOh
  • 87
  • 1
  • 9
1
vote
2 answers

Recursive tree folder function php not going into subfolders

I am currently working on a php file indexer and I need to create a recursive function to create an array that will contains the files and subfolders list of the parent folder, with the subfolders also being arrays containing their files and their…
LLEGIT
  • 13
  • 3
1
vote
1 answer

segfault on readdir call

I'm trying to perform a readdir(): here is the code: DIR *dp; struct dirent *dirp; if (dp = opendir("saves") == NULL) { my_printf("Cannot open saves directory.\n"); return 84; } else if ((dirp = readdir(dp)) == NULL) { …
Grainbox
  • 31
  • 3
1
vote
0 answers

file order variation in ext3 filesystem

I have a program whose output depends on how file order are returned by readdir. Is there any way to simulate different file return order over ext3
Ankur Goel
  • 11
  • 1
1
vote
0 answers

Unable to access file on local http-server from javascript fs

I'm trying to access the directory listing of files from the http-server webserver listing configured on the localhost:4040. I have uploaded files using the http-server to mimic a file server for testing. When I use fs to access the files in the…
Ben
  • 11
  • 1
1
vote
1 answer

php finding the names of the folders and then the files in there?

I am trying to use php to look in a folder and there will be five folders within that ....i want to display the name as the folder as the ul and the names of that folders files as li's..... here is my code I i creaded to create the inner li's but…
Matt Elhotiby
  • 43,028
  • 85
  • 218
  • 321
1
vote
1 answer

Nodejs how to read directory and grab certain files

in my Nodejs project, i have a folder named input that contains green-1.png, green-2.png, green-3.png,red-1.png, red-2.png, red-3.png files i want to read the input directory and grab only the all the green files. i tried this code : const {…
mohamed mostapha
  • 161
  • 4
  • 16
1
vote
2 answers

Fill a dynamic 2D array with words of multiples text files in C

with this C code I want to fill a dynamic array of char with the words parsed in each differents text files returned by the readdir function. #include #include
1
vote
0 answers

PHP correct while-loop: (false !== ($file = readdir($handle))) is not showing recent files changes with MAMP on OSX

By now I'm convinced that I must be one of the few who experienced something like this. The problem is that my PHP is not listing updates (or recent file changes) in a certain directory. Say I have 3 files: 1.jpg 2.jpg 3.jpg When I do something like…
Francis Laclé
  • 384
  • 2
  • 6
  • 22
1
vote
1 answer

A readdir() issue

My intention is to read every directory and file rooted at a directory given as input in a depth-first manner and towards it I had written a portion(very very initial) of code as shown below. int main() { DIR *fd_dir; struct dirent *s_dirent; …
Lipika Deka
  • 3,774
  • 6
  • 43
  • 56
1
vote
1 answer

To count files present in a directory with specific extension in node.js

In a given task,I need to count file with extensions such as '.js','.txt' and other remaining extensions by using promise. const fs = require("fs"); const path = require("path"); function fun(pathTodirectory) { return new Promise(resolve => { …
1
vote
1 answer

Reading only .txt files from an input directory, then getc all contents into one array in C

So I am attempting to make a function that receives an input directory, examine only its ".txt" files and then store ALL contents into one character array (dynamically allocated, here). As I use getc() on every character in each file, one at a…
PluffTed
  • 53
  • 5
1
vote
0 answers

inode number is changed suddenly at certain location in c programming on linux

#include #include #include #include #include #include #include #include void creatEnv(); char *mygetcwd(char *buf, size_t size) { DIR *dirp_p,…
ben kwon
  • 61
  • 4