Questions tagged [opendir]

A PHP, PERL, C library function for opening a directory handle. Questions are about the workings or issues with the opendir function.

The opendir() function is used to open up a directory handle to be used in subsequent closedir(), readdir(), and rewinddir() calls.

Links:

Related

262 questions
24
votes
5 answers

C faster way to check if a directory exists

I'm using opendir function to check if a directory exists. The problem is that I'm using it on a massive loop and it's inflating the ram used by my app. What is the best (fastest) way to check if a directory exists in C? What is the best (fastest)…
Frederico Schardong
  • 1,946
  • 6
  • 38
  • 62
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
20
votes
4 answers

Open directory using C

I am accepting the path through command line input. When I do dir=opendir(args[1]); it doesn' t enter the loop...i.e dir==null... How do I pass the command line input to dir pointer? void main(int c,char **args) { DIR *dir; struct dirent…
Vinod K
  • 1,885
  • 11
  • 35
  • 45
18
votes
6 answers

PHP opendir() to list folders only

I would like to use opendir() to list only the folders in a particular folder (i.e. /www/site/). I would like to exclude files from the list as well at the '.' and '..' folders that appear on a linux folder listing. How would I go about doing…
Jeff Thomas
  • 4,728
  • 11
  • 38
  • 57
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
3 answers

Should Perl's opendir always return . and .. first?

opendir MYDIR, "$dir"; my @FILES = readdir MYDIR; closedir MYDIR; It appears that 99.9 % of the time the first two entries in the array are always “.” and “..”. Later logic in the script has issues if it is not true. I ran into a case…
ojblass
  • 21,146
  • 22
  • 83
  • 132
8
votes
4 answers

Get filenames of images in a directory

What should be done to get titles (eg abc.jpg) of images from a folder/directory using PHP and storing them in an array. For example: a[0] = 'ac.jpg' a[1] = 'zxy.gif' etc. I will be using the array in a slide show.
Hammad Khalid
  • 538
  • 3
  • 7
  • 21
6
votes
3 answers

C: Checking the type of a file. Using lstat() and macros doesn't work

I use opendir() to open a directory and then readdir() and lstat() to get the stats of each file in that directory. Following this manpage I wrote the code under which doesn't work as thought. It does list all the files in the current directory but…
Pithikos
  • 18,827
  • 15
  • 113
  • 136
6
votes
6 answers

Which is faster: glob() or opendir()

Which is faster between glob() and opendir(), for reading around 1-2K file(s)?
ariefbayu
  • 21,849
  • 12
  • 71
  • 92
5
votes
4 answers

How to search file in folder by using php?

I have a folder called allfiles, and there are some files in this folder, such as 1212-how-to-sddk-thosd.html 3454-go-to-dlkkl-sdf.html 0987-sfda-asf-fdf-12331.html 4789-how-to-fdaaf-65536.html I use scandir to list all files, and now I need to…
user2688045
4
votes
2 answers

Opendir error; No such file or directory found

This may be a very easy question. I am working in directory /mobile and I have photos in a directory /uploads. I am getting the error: Warning: opendir(http://www.yoozpaper.com/uploads) [function.opendir]: failed to open dir: not implemented in…
stevieD
  • 135
  • 2
  • 5
  • 14
4
votes
2 answers

Path to a file in a different drive?

My php file is here: D:/Appserv/www/x/y/file.php I want to load stuff from this folder: E:/foldie I don't know what path will lead me there. $somePath="HELP ME HERE!!!!" $dir=opendir($somePath); //looping through filenames while (false !==…
navand
  • 1,379
  • 1
  • 16
  • 20
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
1 answer

C opendir() not opening a directory?

I'm not all that experienced in C, but have an assignment in one of my classes, and I'm having a few issues opening a directory. The purpose of the program is to (paraphrased): If no flag or directory is provided, list names of files in current…
TheAshenKnight
  • 108
  • 1
  • 6
4
votes
3 answers

Can't open directory, or what's wrong with my (Perl) code?

I have a file name logspath.txt which contain on the logs directory path on the machine. one directory each line. Although the directory exist, Perl say it doesn't. #!/usr/bin/perl -w open FILE,"logspath.txt" or die $!; while (){ print…
DoronS
  • 347
  • 1
  • 6
  • 12
1
2 3
17 18