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
4
votes
3 answers

Readdir/closedir - Valgrind shows "invalid read"

Posting snippets of my code here. I am trying to get a footing around debugging. struct dirent *s_dirent; char path[300]; .... bzero(path,300); ... fd_dir = opendir(path); while((s_dirent = readdir(fd_dir))!=NULL) { if(s_dirent->d_name[0] ==…
Lipika Deka
  • 3,774
  • 6
  • 43
  • 56
4
votes
1 answer

Having a dirent that is a symbolic link, how can I get the link-target's path name?

Having opened a directory with opendir() and using readdir() to read out it's entries, I check whether the entry is a symbolic link and if so I'd like to use the name of the target. (Let's say we have a directory exampledir, in it a file that's a…
zaep
  • 73
  • 1
  • 4
4
votes
4 answers

Perl Program to efficiently process 500,000 small files in a directory

I am processing a large directory every night. It accumulates around 1 million files each night, half of which are .txt files that I need to move to a different directory according to their contents. Each .txt file is pipe-delimited and contains…
DenairPete
  • 61
  • 1
  • 4
4
votes
6 answers

php readdir problem with japanese language file name

I have the following code \n"; } } …
Mr Bosh
4
votes
3 answers

is_dir doesn't recognize directories. Why?

I have this function: if (is_dir($dir)) { //are we able to open it? if ($dh = opendir($dir)) { //Let's cycle while (($subdir = readdir($dh)) !== false) { if ($subdir != "." && $subdir != "..")…
0plus1
  • 4,475
  • 12
  • 47
  • 89
4
votes
10 answers

PHP readdir with european characters

I get images files which have Czech characters in the filename (eg, ěščřžýáíé) and I want to rename them without the accents so that they are more compatible for the web. I thought I could use a simple str_replace function but it doesn't seem to…
aland
  • 1,824
  • 2
  • 26
  • 43
4
votes
5 answers

PHP readdir( ) returns " . " and " .. " entries

I'm coding a simple web report system for my company. I wrote a script for index.php that gets a list of files in the "reports" directory and creates a link to that report automatically. It works fine, but my problem here is that readdir( ) keeps…
DWilliams
  • 451
  • 8
  • 22
4
votes
1 answer

What guarantees does pathconf(..., _PC_NAME_MAX) provide?

Context: The readdir_r function is used to read the next entry from a DIR* (there's also readdir, but that's not thread-safe). readdir_r takes a pointer to a user-allocated buffer to hold the output dirent. The manpage indicates that the size…
John Bartholomew
  • 6,428
  • 1
  • 30
  • 39
3
votes
1 answer

PHP Recursively File Folder Scan Sorted by Modification Date

I'm using this script to see all subfolders and files of subfolders function readfolder($dir) { global $tfile,$tdir;$i=0;$j=0;$myfiles; $myfiles[][] = array(); if (is_dir($dir)) { if ($dh = opendir($dir))…
Goldie
  • 1,570
  • 5
  • 21
  • 33
3
votes
1 answer

How to mock fs.readdir in jest node.js

In my node.js app, I've written code to read files from a directory using await fs.readdir. When I try to test the code using jest, I can't mock the readdir function. I'm attaching the code. const util = require('util'); const readdir =…
Anjana
  • 366
  • 5
  • 21
3
votes
1 answer

Can you make Julia's readdir() function differentiate files from directories?

Julia's readir lists a directory but it doesn't say if the items are files or directories. Is there any way to toggle this?
cybervigilante
  • 231
  • 1
  • 5
3
votes
2 answers

How can I get node.js to return data once all operations are complete

I am just learning server-side JavaScript so please bear with any glaring mistakes I've made. I am trying to write a file parser that operates on HTML files in a directory and returns a JSON string once all files have been parsed. I started it with…
DewBoy3d
  • 163
  • 3
  • 16
3
votes
2 answers

Perl readdir as a one-liner?

As of now, I know of two ways to open and read a directory in Perl. You can use opendir, readdir and closedir or you can simply use glob to get the contents of the directory. Example: Using opendir, readdir and closedir: opendir my $dh,…
tjwrona1992
  • 8,614
  • 8
  • 35
  • 98
3
votes
2 answers

How do i get readdir ignore directories in C/C++?

I am reading the content of the current library with readdir, but I would like to treat only files and not directories. How do I know that I am pointing to a directory and not to a file?
Debugger
  • 9,130
  • 17
  • 45
  • 53
3
votes
3 answers

C - Linux Sparse File: How to check if file is sparse and print 0-filled disk blocks

What I am trying to do is to write a C program on linux which should be checking in the current directory if there are sparse files, and also I would like to print the number of disk blocks that already represent gaps in the file and the number of…
user2965601
1 2
3
20 21