Questions tagged [scandir]

List files and directories inside the specified path

PHP usage:

array scandir ( string $directory [, int $sorting_order = SCANDIR_SORT_ASCENDING [, resource $context ]] )

Returns an array of filenames on success, or FALSE on failure. If directory is not a directory, then boolean FALSE is returned, and an error of level E_WARNING is generated.

338 questions
5
votes
2 answers

Is scandir really thread safe?

In the UNIX® System Threads Reference, under the heading of "Thread-safety" is a list of functions are "not guaranteed to be thread-safe on all UNIX systems." The function scandir() is absent from this list, while readdir() appears on the list. …
Mike Godin
  • 2,890
  • 2
  • 23
  • 26
5
votes
1 answer

Filtering scandir for filenames in folder C Language

I am using scandir() function in C, on a folder where i need to get files whose filenames are exactly = "exe". How can i filter the entries returned by scandir? Third argument of scandir is filter: int scandir(const char *dirp, struct dirent…
Antonio Falcone
  • 171
  • 3
  • 17
4
votes
1 answer

Access External NAS /Volume via scandir in PHP on Mac

I've done a bunch of research on this one and there are very different answers. I can't get confident that I won't mess up my Apache settings or cause me not to be able to get to the Volume from Mac Finder after making changes. Has anyone done this…
Jeff Solomon
  • 407
  • 6
  • 20
4
votes
1 answer

Why is os.scandir() as slow as os.listdir()?

I tried to optimize a file browsing function written in Python, on Windows, by using os.scandir() instead of os.listdir(). However, time remains unchanged, about 2 minutes and a half, and I can't tell why. Below are the functions, original and…
Vlad Iordache
  • 428
  • 1
  • 3
  • 13
4
votes
3 answers

PHP scandir results: sort by folder-file, then alphabetically

PHP manual for scandir: By default, the sorted order is alphabetical in ascending order. I'm building a file browser (in Windows), so I want the addresses to be returned sorted by folder/file, then alphabetically in those subsets. Example: Right…
Ben
  • 47,286
  • 44
  • 159
  • 208
4
votes
1 answer

ImportError on scandir

I am trying to use the scandir package as an alternative to os.walk in python 2.7. However, during import an ImportError is raised as follows. Python 2.7.12 (default, Jul 1 2016, 15:12:24) [GCC 5.4.0 20160609] on linux2 Type "help", "copyright",…
4
votes
3 answers

Create os.DirEntry

Does anyone have a hack to create an os.DirEntry object other than listing the containing directory? I want to use that for 2 purposes: tests API where container and contained are queried at the same time
Dima Tisnek
  • 9,367
  • 4
  • 48
  • 106
4
votes
3 answers

php scandir produces extra elements (2 dots)

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); …
Cain Nuke
  • 1,865
  • 4
  • 29
  • 52
4
votes
1 answer

how can I parameterize select function in scandir

The scandir() function scans the directory dir, calling select() on each directory entry as "int(*filter)(const struct dirent *)" How can I pass pattern value as parameter to fnmatch(const char *pattern, const char *string, int flags) function used…
famedoro
  • 1,143
  • 2
  • 14
  • 37
4
votes
2 answers

How to get filtered file name list using scandir in PHP?

I would like to get all files that has '_img' and PDF type in a folder Instead of using $fileArray = scandir($dir); foreach ($fileArray as $file) { if (preg_match("_img",$file) && pathinfo($file, PATHINFO_EXTENSION) == 'pdf'){ …
user782104
  • 12,011
  • 51
  • 154
  • 289
4
votes
1 answer

PHP Scandir Not Automatically in Alphabetical Order?

TIA. With my remedial PHP skills, I can't figure out why scandir isn't automatically sorting alphabetically. (It would also be nice to have folders grouped together and sorted alphabetically and files grouped together and sorted alphabetically,…
WGD
  • 43
  • 4
4
votes
1 answer

Open every file but not links to other directories when using scandir()

I want to recursively copy one directory into another (like cp -R) using POSIX scandir(). The problem is that when I copy a directory like /sys/bus/, which contains links to higher levels (for example: foo/foo1/foo2/foo/foo1/foo2/foo/... ) the…
Andrea
  • 3,322
  • 3
  • 28
  • 45
3
votes
3 answers

look for a specific filetype in a directory in php and send it to a different directory after conversion

I have a directory in which there is a mp4 file (including other files as well) which I want to convert into mp3 and then send it to different directory. I have used the following command line command to covert into mp3 and its working perfectly…
flash
  • 1,564
  • 3
  • 27
  • 87
3
votes
1 answer

asd.jpg is not a valid JPEG file - Scandir PHP

I have a software that upload each minute a jpeg into FTP account. In PHP i make a little PHP code in crontab that take last JPEG file and performs graphics processing. This work fine. $all_files = scandir("./dir/dir",1); $last_files =…
3
votes
1 answer

AttributeError: 'module' object has no attribute 'scandir'

I have no idea why this is happening. Here's the function: def scanWallDir(basedir, scansubdirs=True): wallsOut = [] for entry in os.scandir(basedir): if entry.is_file(): print(("file " + entry.name)) elif…
Aido
  • 1,358
  • 2
  • 14
  • 37
1
2
3
22 23