Canttouchit
Canttouchit

Reputation: 3159

FilesystemIterator is not working

I try to run on all files in /images directory and I get disconnected when I reach the constructor part the directory is in the same directory as my php file:

$it = new FilesystemIterator('./images/');
foreach ($it as $fileinfo) {
    echo $fileinfo->getFilename() . "\n";
}

The error I see is:

PHP Fatal error: Uncaught exception 'UnexpectedValueException' with message 'FilesystemIterator::__construct(/images/,/images/): The system cannot find the file specified. (code: 2)' in D:\wamp\www\MyHome2\php\images.php:9

Upvotes: 3

Views: 3515

Answers (2)

mnagel
mnagel

Reputation: 6854

you are (probably) using absolute paths when you want relative paths. use

$it = new FilesystemIterator('./images/');

or in your case, where you need to move "up" one folder, use ".." to move up:

$it = new FilesystemIterator('./../images/');

Upvotes: 4

Prisoner
Prisoner

Reputation: 27628

Your path doesn't exist, you're using an absolute path, change it to relative or give the correct full path.

Example absolute:

D:\wamp\www\MyHome2\php\images

example relative:

./images/

You can read about how paths work in file systems here: http://en.wikipedia.org/wiki/Path_(computing)

Upvotes: 2

Related Questions