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
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
  • 1
  • 5
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
  • 4,262
  • 4
  • 37
  • 56
3
votes
1 answer

Php scandir() problems

I was wondering, my Scandir() function works on a php $_GET variable, so the variable returns the folder, but I'm having a problem because I'm not sure how to echo out an error if there is a problem with with directory. this is the error I am…
Aiden Ryan
  • 845
  • 2
  • 11
  • 15
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,455
  • 11
  • 61
  • 132
3
votes
3 answers

List all folders in directory (PHP)

How can I make my code only display links to the folders and not the files in the directory? $d = dir("."); echo "
    "; while(false !== ($entry = $d->read())) { echo "
  • {$entry}
  • "; } echo "
"; $d->close();
user5352189
3
votes
2 answers

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

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…
user4085386
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
6 answers

Where does "." (dot) come from when using PHP ´scandir´

I'm a bit confused. I'm building a PHP function to loop out images in a specified dir. PHP $dir = "bilder/".$objekt[0]['objekt_nr']."/thumbnail/"; $thumbnails = scandir($dir); print_r($thumbnails); foreach ($thumbnails as $value) { echo "
Björn C
  • 3,860
  • 10
  • 46
  • 85
3
votes
3 answers

How to get only video files from folder directory of all files in php?

I have some videos,images and text files in "uploads/video/" dir. Here i am getting all the files using scandir but I want only videos from that folder. Sample code : $video_dir = 'uploads/video/'; $video_array =…
Ramalingam Perumal
  • 1,367
  • 2
  • 17
  • 46
3
votes
2 answers

PHP scandir failing in Laravel

So I'm trying to pass a directory to a model function in my Laravel application that uses PHP's scandir, and it can't seem to find the directory. The string/path I'm supplying to scandir is /staffportal/public/public/documents/ra_docs/. The…
kibowki
  • 4,206
  • 16
  • 48
  • 74
3
votes
2 answers

Is it safe to use array_slice to remove scandir dot and dot-dot entries?

I want to use array_slice with scandir in my PHP script. Normal usage:
Temüjin
  • 15,371
  • 8
  • 35
  • 57
3
votes
3 answers

Implicit declaration of scandir; alphasort is undeclared

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:…
Bluedanes
  • 35
  • 1
  • 5
3
votes
1 answer

How to access a remote directory and copy files in PHP

I want to copy files from a remote directory. But I don't know how to write its UNC. I can use file://Server/Production/Images to open the directory in a browser, but it can't work if I just use this path in my PHP script. $origin =…
asdk77
  • 143
  • 1
  • 2
  • 12
3
votes
3 answers

In c++11 passing a lambda function to scandir is probably impossible. What's the next best thing?

I need an instance method or a lambda function or it's equivalent to be passed as the select function argument to scandir. Is there any way to do this? The key thing I'm trying to achieve is to have the select function (the callback) see different…
Phill Apley
  • 923
  • 10
  • 16
3
votes
2 answers

Scan directory tree efficiently by date

What's the most efficient way to grab a list of new files after a given date in php, or perhaps using a system call? I have full control over how the files are stored as I receive them, so I thought maybe storing them in a folder structure like…
Eric
  • 186
  • 1
  • 10
1 2
3
23 24