readdir

PHP Get dimensions of images in dir

余生颓废 提交于 2019-12-01 09:31:26
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 code reads the dir and all the sub dirs. But the moment I try to extract the dimensions the loop halts at 8% of all the pictures that need checking. Could it be PHP is not allowed to do more calculations? What is going on!? This is how far I got: checkDir('dir2Check'); function checkDir($dir, $level = 0) { if ($handle = opendir($dir)) { while (false !

Efficiently Traverse Directory Tree with opendir(), readdir() and closedir()

限于喜欢 提交于 2019-11-30 06:42:06
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 of the files, so I could either append that name to the directory path and stat() and opendir() them, or I could change the current working directory of the process via chdir() and roll it back via chdir(".."). The problem with the first approach is that if the

List regular files only (without directory) problem

南楼画角 提交于 2019-11-29 16:30:30
Do you know why certain files 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 stat info; // info about the file. while (file = readdir(dh)) { stat(file->d_name, &info); printf("note: file->d_name => %s\n", file->d_name); printf("note: info.st_mode => %i\n", info.st_mode); if (S_ISREG(info.st_mode)) printf("REGULAR FILE FOUND! %s\n", file->d_name); }

readdir() beginning with dots instead of files [duplicate]

自作多情 提交于 2019-11-29 14:21:38
This question already has an answer here: Why do directory listings contain the current (.) and parent (..) directory? 8 answers I have a little problem. I'm reading files from directory and it works, but it read two extra files on the beginning ...what is it? for example, there is a list of files: "A348", "A348A", "A348B" and this is what i get: ".", "..", "A348", "A348A", "A348B" ??? DIR *dir; struct dirent *dp; char * file_name; while ((dp=readdir(dir)) != NULL) { file_name = dp->d_name; } nio . is a directory entry for current directory .. is a directory entry for the directory one level

Efficiently Traverse Directory Tree with opendir(), readdir() and closedir()

試著忘記壹切 提交于 2019-11-29 06:18:29
问题 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 of the files, so I could either append that name to the directory path and stat() and opendir() them, or I could change the current working directory of the

Return Perl-output to PHP

偶尔善良 提交于 2019-11-28 14:41:29
I want to return the output of a perl script to a webpage. However it only returns the last line. Perl script: my $directory = $ARGV[0]; opendir(DIR,$directory); my @files = grep {/\.txt$/ } readdir(DIR); closedir(DIR); foreach(@files) { print $_."\n"; } PHP code: $perl_result = exec("perl $script_folder $project_folder"); *some code* <?php print $perl_result; ?> Expected output (and what the script returns in a Linux command line): test.txt test2.txt test3.txt What PHP returns: test3.txt What do I have to change in my code to get PHP to show all lines? Thanks Quoting from the PHP manual page

List regular files only (without directory) problem

烈酒焚心 提交于 2019-11-28 10:23:59
问题 Do you know why certain files 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 stat info; // info about the file. while (file = readdir(dh)) { stat(file->d_name, &info); printf("note: file->d_name => %s\n", file->d_name); printf("note: info.st_mode => %i

readdir() beginning with dots instead of files [duplicate]

我们两清 提交于 2019-11-28 07:52:45
问题 This question already has an answer here: Why do directory listings contain the current (.) and parent (..) directory? 8 answers I have a little problem. I'm reading files from directory and it works, but it read two extra files on the beginning ...what is it? for example, there is a list of files: "A348", "A348A", "A348B" and this is what i get: ".", "..", "A348", "A348A", "A348B" ??? DIR *dir; struct dirent *dp; char * file_name; while ((dp=readdir(dir)) != NULL) { file_name = dp->d_name; }

Members of Dirent structure

元气小坏坏 提交于 2019-11-28 06:24:15
I have started working with dirent.h library and I came across a very useful member of "struct dirent" structer which struct dirent *p->d_name in my book. But unfortunatly it doesn't states any other members of this structure; I was wondering what else are the members of this structure and what are they used for? Regards The structure, struct dirent refers to directory entry. http://www.gnu.org/software/libc/manual/html_node/Directory-Entries.html In linux it is defined as: struct dirent { ino_t d_ino; /* inode number */ off_t d_off; /* offset to the next dirent */ unsigned short d_reclen; /*

Return Perl-output to PHP

一世执手 提交于 2019-11-27 08:53:25
问题 I want to return the output of a perl script to a webpage. However it only returns the last line. Perl script: my $directory = $ARGV[0]; opendir(DIR,$directory); my @files = grep {/\.txt$/ } readdir(DIR); closedir(DIR); foreach(@files) { print $_."\n"; } PHP code: $perl_result = exec("perl $script_folder $project_folder"); *some code* <?php print $perl_result; ?> Expected output (and what the script returns in a Linux command line): test.txt test2.txt test3.txt What PHP returns: test3.txt