readdir

Why can't I open files returned by Perl's readdir?

怎甘沉沦 提交于 2019-12-28 07:07:19
问题 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 open file: Permission denied" error. Why is this happening with the same directory , the same files and the same me as Administrator. Can someone kindly show me

get image files from directory on server for further processing

我的梦境 提交于 2019-12-25 18:23:18
问题 I have folders on the server that contain image files. I'm trying to get those files and then upload them further, but I think I'm using the wrong function. My code: $dir = "../uploads/".$folderimage."/"; if ($handle = opendir($dir)) { while (false !== ($entry = readdir($handle))) { if ($entry != "." && $entry != "..") { echo "$entry\n"; $handle = fopen($entry,"wb"); $mug->images_upload(array( "AlbumID" => "#####", "File" => $handle)); } } closedir($handle); } Not sure what I am doing, all I

how do I exclude non-folders files from this readdir function?

徘徊边缘 提交于 2019-12-25 04:56:34
问题 The following lists the folders, the index.php and the favicon.ico in the directory. I want to see only folders. Any ideas? Thanks. <?php // opens this directory $myDirectory = opendir("."); // gets each entry while($entryName = readdir($myDirectory)) { $dirArray[] = $entryName; } // closes directory closedir($myDirectory); // counts elements in array $indexCount = count($dirArray); // sorts files sort($dirArray); // print 'em print("<table width='100%' cellspacing='10'> <tr> </tr>\n"); //

PHP readdir with european characters

假装没事ソ 提交于 2019-12-23 13:40:08
问题 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 readdir, after checking for extension. function readFiles($dir, $ext = false) { if (is_dir($dir)) { if ($dh = opendir($dir)) { while (($file = readdir($dh)) !==

PHP readdir and sort

走远了吗. 提交于 2019-12-23 10:58:06
问题 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 while ($file = readdir($dir)) // while loop { $parts = explode(".", $file); // pull apart the name and dissect by period if (is_array($parts) && count($parts) > 1) { // does

Start new column when readdir moves to new dir

删除回忆录丶 提交于 2019-12-20 05:44:28
问题 Original Issue: I am using readdir to snag file names from multiple directories. I was wondering if there is a way to arrange the data so that each time it starts a new directory it makes a new column i.e. ---| user1 | user2 | user3 | ---| file1a | file2a | file3a | ---| file1b | file2b | file3b | ---| file1c | file2c | file3c | ---| file1d | ^ | file3d | ---| file1e | | | ^ | ---| ^ | end | | | ---| | | dir2 | end | ---| end | #start | dir3 | ---| dir1 | col3 | etc. | ---| #start | | | ---|

Members of Dirent structure

不打扰是莪最后的温柔 提交于 2019-12-17 18:04:42
问题 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 回答1: 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

How to use S_ISREG() and S_ISDIR() POSIX Macros?

为君一笑 提交于 2019-12-17 09:45:56
问题 This is a C program I wrote to recursively navigate and output directories and regular files. It compiles and runs fine on my Linux machine. But on Solaris, the dit->d_type == 8 check and the other similar ones don't work because there is no d_type field. An answer I've read to this problem is to use the S_ISREG() and S_ISDIR() macros, but they don't work at all the way I have them in my code currently. I commented out the lines that work on my Linux machine. #include <sys/types.h> #include

Microsoft Visual Studio: opendir() and readdir(), how?

隐身守侯 提交于 2019-12-17 04:07:10
问题 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 another included files inside those files ..., and by looking in the files i see mingw stuff there so its compiler related? idk what compiler MSVC++ uses, but is it possible to

Print files and subdirectories of given directory

故事扮演 提交于 2019-12-13 02:25:51
问题 I am trying to get all files and directories from a given directory but I can't specify what is the type (file/ directory). Nothing is being printed. What I am doing wrong and how to solve it. Here is the code: sub DoSearch { my $currNode = shift; my $currentDir = opendir (my $dirHandler, $currNode->rootDirectory) or die $!; while (my $node = readdir($dirHandler)) { if ($node eq '.' or $node eq '..') { next; } print "File: " . $node . "\n" if -f $node; print "Directory " . $node . "\n" if -d