scandir

PHP RecursiveDirectoryIterator

為{幸葍}努か 提交于 2019-12-17 20:46:41
问题 I want to do a RecursiveDirectoryIterator on a set of folders in a directory, say ./temp and then list the files in each folder according to the name of the folder. For example I have the folders A and B . In A, I have a list of files say, 1.txt , 2.php , 2.pdf , 3.doc , 3.pdf . In B, I have 1.pdf , 1.jpg , 2.png . I want my results to be like this: A => List of files in A B => List of files in B How can this be done? <?php $scan_it = new RecursiveDirectoryIterator("./temp"); foreach(new

Implicit declaration of scandir; alphasort is undeclared

三世轮回 提交于 2019-12-13 16:26:39
问题 I am trying to use scandir to print a list of files in the current directory. When I try to compile, I am receiving the following errors and warnings: warning: implicit declaration of function ‘scandir’ [-Wimplicit-function-declaration] error: ‘alphasort’ undeclared (first use in this function) note: each undeclared identifier is reported only once for each function it appears in I am including <dirent.h> , which to my knowledge should define scandir() and all related functions. And I don't

scnadir sort order asc put uppercase letters first

醉酒当歌 提交于 2019-12-13 07:59:56
问题 So I am trying to sort a list of folders and files and display them alphabetical the problem appears that if someone created a folder that starts with a captial letter that folder appears first for example if I had the following folders Array ( [0] => . [1] => .. [2] => _base [3] => template [4] => Website ) I would expect when using scandir ( scandir($directory, SCANDIR_SORT_ASCENDING) ) to see the folders listed out as above but instead that get listed out as Array ( [0] => . [1] => .. [2]

RecursiveDirectoryIterator gives exception

假装没事ソ 提交于 2019-12-13 02:19:43
问题 RecursiveDirectoryIterator gives Unexpected Value Exeception $path= WEB."sync_content/offer/"; $files = new RecursiveIteratorIterator( new RecursiveDirectoryIterator($path), RecursiveIteratorIterator::LEAVES_ONLY ); foreach ($files as $name => $file) { $fn=$file->getFilename(); if($fn!='.' && $fn!='..' && !is_dir($fn)) { $filePath = $file->getRealPath(); $zip->addFile($filePath,$fn); } } And the error is: fatal error Uncaught exception 'UnexpectedValueException' with message

How to sort files in some directory by the names on Linux

时光毁灭记忆、已成空白 提交于 2019-12-12 07:07:01
问题 I use opendir() and readdir() to display the file names in a directory. But they are disordered. How can I sort them? The language is C. 回答1: The idiomatic way to sort something in C is to use the qsort() function. For this to work, it's best if you can arrange to have all the file names collected into an array of pointers, and then you sort the array. This is not too hard, but it does require either a bit of dynamic-array management, or that you introduce static limits on things (maximum

Search and list specific directories only?

空扰寡人 提交于 2019-12-11 20:40:32
问题 I want to search and list specific folders only and no matter how deep these folders are kept. For instance, below is how I structure them, local/ app/ master/ models/ views/ slaves/ models/ views/ scr/ models/ index.php And I just want to list the folder of models into an array, local/app/master/models/ local/app/slaves/models/ local/models/ My working code, $directories = array(); $results = array_diff( scandir("local"), array(".", "..") ); foreach ($results as $result) { if (is_dir("local/

PHP scandir - multiple directories

痴心易碎 提交于 2019-12-11 09:58:35
问题 I am creating a WordPress plugin which allows a user to apply sorting rules to a particular template (page, archive, single etc). I am populating list of pages using PHP scandir like so: $files = scandir(get_template_directory()); The problem is that I keep single.php templates in a '/single' subfolder so these templates are not being called by the above function. How can I use multiple directories within the scandir function (perhaps an array?) or will I need a different solution? So

Directory listing with wildcards in C

扶醉桌前 提交于 2019-12-11 02:36:20
问题 Is there a ready-made function in C that can list the contents of a directory using wildcards to filter out file names, for example, the equivalent of: echo [!b]???? which shows the names of directory entries that are four characters long and do not start with "b"? I know I can use scandir , but then, I need to provide my own filter function: #include <stdio.h> #include <stdlib.h> #include <dirent.h> int filter(const struct dirent *entry) { if (strlen(entry->d_name) == 4 && entry->d_name[0] !

How to serialize a scandir.DirEntry in Python for sending through a network socket?

筅森魡賤 提交于 2019-12-11 01:34:55
问题 I have server and client programs that communicate with each other through a network socket. What I want is to send a directory entry ( scandir.DirEntry ) obtained from scandir.scandir() through the socket. For now I am using pickle and cPickle modules and have come up with the following (excerpt only): import scandir, pickle s = scandir.scandir("D:\\PYTHON") entry = s.next() data = pickle.dumps(entry) However, I am getting the following error stack: File "untitled.py", line 5, in <module>

php scandir produces extra elements (2 dots)

拜拜、爱过 提交于 2019-12-11 00:57:47
问题 Hi, I have the following files in a directory called content: index.php, page1.php, page2.php and page3.php ONLY. Then I have this code: $column = scandir("content"); foreach ($column as $value) { $stvalue = str_replace(".php", "", $value); echo "<div>$stvalue</div>"; } Nevertheless, this is what I get: <div>.</div> <div>..</div> <div>index</div> <div>page1</div> <div>page2</div> <div>page3</div> Whats with the first 2 elements? I dont have files named like that so I dont get it. Thank you.