views:

21

answers:

1

I'm familiar with the basic of CLI and $argv array with php. Example:

<?php // test.php
var_dump($argv);
?>

$php test.php datafile.txt 10 100

will produce:

array(4) {
  [0]=>
  string(8) "test.php"
  [1]=>
  string(12) "datafile.txt"
  [2]=>
  string(2) "10"
  [3]=>
  string(3) "100"
}

What I'm trying to do is pass all files in a directory *.txt to php. Is there way I can do $php test.php *.txt and have all the filenames stored in an array?

Edit: for the solution I just use the glob function

<?php
$files = glob($argv[1]);

?>
+1  A: 

Take a look at the glob function. I assume you would just call it for every argument, using the argument as the parameter and merge the resultant arrays using array merge.

Yacoby
I'll look into glob. It's looks like a possible solution
Yada