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

Geting numbers of files in specific directory in Linux

Is there anyway to get the total number of files in a specific directory not iterating readdir(3)? I mean only direct members of a specific directory. It seems that the only way to get the number of files is calling readdir(3) repeatedly until it…
cinsk
  • 1,576
  • 2
  • 12
  • 14
3
votes
3 answers

Reading directories using readdir_r

I've been checking and fighting with this procedure without success for quite a while, hope you can help me out. The idea is to read the directory stored in c_Localpath and copy the read dirs into c_namesLocal to return them. Am I doing something…
Guillermo Gruschka
  • 167
  • 1
  • 3
  • 16
2
votes
2 answers

PHP Get dimensions of images in dir

I have a huge ammount of photos that need sorting through. I need to know the dimensions of each photo in order to know or it needs re-sizing. As a programmer I'm convinced there must be a quicker way of doing this. I got quite far. The following…
SKuijers
  • 406
  • 7
  • 18
2
votes
1 answer

How do I add all the files in the current directory to an array from a thread in c?

#include #include #include #include pthread_mutex_t mut1 = PTHREAD_MUTEX_INITIALIZER, mut2 = PTHREAD_MUTEX_INITIALIZER, mut3 = PTHREAD_MUTEX_INITIALIZER, mut4 =…
Chris
  • 402
  • 1
  • 5
  • 18
2
votes
1 answer

Scanning a directory and modify file in c

I'm trying to create a function that scans a folder on my Windows PC and every time it does, a file called "Filter.txt" is appended with the string "Test Script". Now the problems are 2, the first is that the scan must be performed either in the…
AleMal
  • 1,977
  • 6
  • 24
  • 49
2
votes
2 answers

Differentiating between files and directories on linux in C

I have a function that takes in an argument which is a file path. That path is then used in conjunction with the readdir function and stat function to print out all of the files and directories in a directory. The issue I have is when I try to sort…
Devin Bowen
  • 127
  • 1
  • 1
  • 13
2
votes
6 answers

php sftp seg fault

What i need to do if next code gives me seg fault ? $handle = opendir("ssh2.sftp://$sftp".'/usr/bin/'); $file = readdir($handle); closedir($handle); where $sftp is $this->_connection = ssh2_connect($this->_server, 22); …
RusAlex
  • 8,245
  • 6
  • 36
  • 44
2
votes
1 answer

Readdir() in a sequential behavior

int indent = 0; int listDir(const char* dirname){ DIR* dir; struct dirent* d; if(!(dir = opendir(dirname))) return -1; while((d = readdir(dir)) != NULL){ if(strcmp(d->d_name, ".") == 0 || strcmp(d->d_name, "..") == 0…
nullptr
  • 127
  • 9
2
votes
3 answers

How to export local folder structure with nodeJS?

Reading directories recursivly is not the problem. There are many good libraries for it, for instance recursive-readdir. I am searching for a solution to extract only the folder structure without any files etc. Example folder…
Michael W. Czechowski
  • 3,366
  • 2
  • 23
  • 50
2
votes
1 answer

struct dirent in C d_name[256] and NAME_MAX definition

I am confused by the use of d_name[256] and NAME_MAX in struct dirent definition. Does d_name[256] mean that the filename length can be atmost 256 character? Then it also mentions NAME_MAX (quoted in the bottom). So, my question is how NAME_MAX…
hi15
  • 2,113
  • 6
  • 28
  • 51
2
votes
2 answers

What is wrong with this header file?

I'm fairly new to C and am starting to learn header files. Whilst using my header I'm getting an error saying invalid type argument of '->' (have struct dirent). I don't understand what this means, I read here that the second argument to -> must be…
jakehimton
  • 101
  • 8
2
votes
1 answer

opendir on ssh2 never stops

I need to fetch some files from the root directory of a distant server through ssh, the local machine uses php7. I've made this script:
OSdave
  • 8,538
  • 7
  • 45
  • 60
2
votes
4 answers

Perl program help on opendir and readdir

So I have a program that I want to clean some text files. The program asks for the user to enter the full pathway of a directory containing these text files. From there I want to read the files in the directory, print them to a new file (that is…
AlphaA
  • 113
  • 2
  • 9
2
votes
2 answers

readdir doesn't get uploaded file by move_uploaded_file

I need to uploaded a file to my server from a input file field and then make a copy of a folder (the file is on a subfolder of it) to another server using FTP. I use move_uploaded_file to upload the file to my server and then I use readdir to…
2
votes
1 answer

C Segfault in readdir after chdir

I am having a weird issue with this C program I'm writing to loop through a directory and open each file to do some work on. My program is located in the parent directory of the directory I'm searching through. In order for fopen to be able to see…