user3369276
user3369276

Reputation: 71

Mentioning directory together with glob

I have this script to access all the xml files in a folder. But how would I specify a directory inside the glob ?

Here's my code :-

foreach (glob("*.xml*") as $filename) {
    echo $filename."<br />";
}

Upvotes: 0

Views: 31

Answers (1)

user2619381
user2619381

Reputation: 217

You can add the directory in this way :-

$dir="dirname/";
foreach (glob("$dir*.xml*") as $filename) {
    echo $filename."<br />";
}

Notice :- When you echo the filename, the directory would come attached to it. So for instance the filename is example.txt, then the output will be dirname/output.txt. You can then use explode to remoe the dir name.

Upvotes: 1

Related Questions