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 timestamp:
1224161460
1228324260
1229698140
I want to read in these directories in numerical order, which wou...
Hello,
I have the following code
<?php
if ($handle = opendir('C:/xampp/htdocs/movies')) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
echo $file."<br />\n";
}
}
closedir($handle);
}
?>
When it does have mb language such as japanese, it doesn't display pro...
I am using Perl readdir to get file listing, however, the directory contains more than 250,000 files and this results long time (longer than 4 minutes) to perform readdir and uses over 80MB of RAM. As this was intended to be a recurring job every 5 minutes, this lag time will not be acceptable.
More info:
Another job will fill the di...
See also: Where in the documentation does it say that while tests readdir for definedness?. (Not a duplicate; just closely related.)
Many people treat the loop below as idiomatic:
while (defined(my $file = readdir($dir)) {
...
}
instead of:
while (my $file = readdir($dir)) {
...
}
because supposedly with the latter vers...
I have a folder and inside that I have many subfolders. In those subfolders I have many .html files to be read. I have written the following code to do that. It opens the parent folder and also the first subfolder and it prints only one .html file. It shows error:
NO SUCH FILE OR DIRECTORY
I dont want to change the entire code. Any mo...
I've used this kind of code in my Dev-cpp before:
if((dh = opendir(folder)) !== false){
while((file = readdir(dh)) !== false){
// do my stuff
}
closedir(dh);
}
But now i am using MSVC++ and i dont know how to add those files there, i tried to copy dirent.h/dir.h/errno.h in there, but it gives another error relating to...
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 this:
opendir(MYDIR, $newpath);
my @files = grep(/abc\*.*/,readdir(MYDIR)); # DOES NOT WORK
I also ...
$dir_handle = @opendir($url) or die("Unable to open $url");
$count = "0";
while ($file = readdir($dir_handle)) {
if (!is_dir($url.'/'.$file) && ($file="*.jpg" || $file="*.gif" || $file="*.png") && $file!="picture0.*") {
$galleryEventFile[$count] = $file;
$count++;
}
}
closedir($dir_handle);
...
I'm making a little gallery. I want to read the file names off a directory and print the file names below after I've stripped some leading numerals and file extensions.
I have two versions of the code.
Version 1 doesn't sort
$current_dir = "$DOCUMENT_ROOT"."/weddings2/";
$dir = opendir($current_dir); // Open the sucker
whil...
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 I pretty much always use readdir.
After thinking over this recent question I realized th...
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 returning the . and .. directory pointers in addition to the directory's contents. Is there ...
Well, I know this is another newbie question but I'm very frustrated and I'm looking to be enlightened again. With the guidance of you guys, I've already learnt how to use the glob function to read the contents of each file in a directory. Now I'm trying the readdir-foreach combination to do the same thing but I keep receiving "Cannot op...
Hello,
Do you know why a lot of file are not listed by this program, even if they are "regular"?
#include <stdio.h>
#include <sys/types.h>
#include <sys/param.h>
#include <sys/stat.h>
#include <dirent.h>
int main(void) {
DIR *dh = opendir("./"); // directory handle
struct dirent *file; // a 'directory entity' AKA file
struct...
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 work the same with the file array as it does with a string literal.
I read the files with re...
know nothing about php, but I have this script that reads a folder and displays a thumbnail gallery, problem is it dosent display alphabetically. Have searched the net and seen that sort does this but have no idea where to start any help would be much appreciated.
heres the script
$sitename = $row_wigsites['id'];
$directory = 'sit...
I am trying to make a lightweight frontend for my fileserver. I use PHP to display all the files, but readdir() is executed as the http user, because apache is started as this user.
This is a problem, because I want to view all my files. Therefore, readdir() has to be run as root, but I don't know how to do that. Can you guys help me?
...
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 would need to recurse into the directory subdirectories.
Of course, they give me the name...
Hello all,
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?
Thank you
...
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 != "..") {
echo $subdir;
}
}
}
This returns:
dire...
Hello,
I'm having problems with a PHP script trying to list images alphabetically. I need this urgently and I have not much knowledge of PHP. I was trying to use scandir() but I'm not succeeding. Thanks for your help!!
Here is the code:
function listerImages($repertoire){
$i = 0;
$repertoireCourant = opendir('./'.$repertoire);
whi...