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.

354 questions
6
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
  • 181
  • 3
  • 17
5
votes
2 answers

using os.scandir() results in 'unresolved attribute reference' warnings in pycharm

I have the following python code in pycharm: # search for files or folders with two or more adjacent spaces def twoplusspaces(path): srchr = os.scandir(path) # get our iterator # iterate through folders and files looking for adjacent blank…
user1800967
  • 953
  • 1
  • 6
  • 11
5
votes
4 answers

How to search file in folder by using php?

I have a folder called allfiles, and there are some files in this folder, such as 1212-how-to-sddk-thosd.html 3454-go-to-dlkkl-sdf.html 0987-sfda-asf-fdf-12331.html 4789-how-to-fdaaf-65536.html I use scandir to list all files, and now I need to…
user2688045
5
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
  • 54,723
  • 49
  • 178
  • 224
5
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
  • 11,241
  • 4
  • 68
  • 120
5
votes
5 answers

PHP: Using scandir(), folders are treated as files

Using PHP 5.3.3 (stable) on Linux CentOS 5.5. Here's my folder structure: www/myFolder/ www/myFolder/testFolder/ www/myFolder/testFile.txt Using scandir() against the "myFolder" folder I get the following results: . .. testFolder testFile.txt I'm…
Reado
  • 1,412
  • 5
  • 21
  • 51
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
  • 3,727
  • 3
  • 27
  • 29
4
votes
1 answer

Error: EPERM: operation not permitted, scandir

please I am running a react native project but when I run the npx react-native run-android command, I get the error below error EPERM: operation not permitted, scandir 'C:/Users/REO/AppData/Local/Application Data'. Error: EPERM: operation not…
Reo
  • 91
  • 1
  • 7
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
  • 459
  • 6
  • 21
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

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
  • 2,843
  • 5
  • 42
  • 65
4
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,524
  • 3
  • 18
  • 41
4
votes
4 answers

How to check a path is a file or folder in PHP

I use scandir() to search files recursively. But if the file path directs to a file not a folder, there will be a warning. How can I check the path whether it directs a file or folder? enter code here
asdk77
  • 143
  • 1
  • 2
  • 12
4
votes
2 answers

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,223
  • 2
  • 17
  • 41
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
  • 13,233
  • 55
  • 172
  • 312
1
2
3
23 24