php - How to pull a directory's files and subdirectories names into an array? -
i'm trying pull names of subdirectories of directory array. i've tried few different things. doing wrong here?
i pulled little function off of php scandir() documentation page.
$data_dir = 'path/to/data_directory/'; function dirtoarray( $data_dir ) { $result = array(); $cdir = scandir( $data_dir ); // line 19 foreach ($cdir $key => $value) { if (!in_array($value,array(".",".."))) { if (is_dir($data_dir . directory_separator . $value)) { $result[$value] = dirtoarray($data_dir . directory_separator . $value); } else { $result[] = $value; } } } return $result; } $data_dir_array = dirtoarray( $data_dir ); print_r( $data_dir_array );
ouput
warning: scandir(/users/alexcory/library/application\ support/alfred\ 2/workflow\ data): failed open dir: no such file or directory in /users/alexcory/library/application support/alfred 2/alfred.alfredpreferences/workflows/user.workflow.36de4754-2c41-4a38-ba8a-ff48d97c6371/open_data.php on line 19
warning: scandir(): (errno 2): no such file or directory in /users/alexcory/library/application support/alfred 2/alfred.alfredpreferences/workflows/user.workflow.36de4754-2c41-4a38-ba8a-ff48d97c6371/open_data.php on line 19
warning: invalid argument supplied foreach() in /users/alexcory/library/application support/alfred 2/alfred.alfredpreferences/workflows/user.workflow.36de4754-2c41-4a38-ba8a-ff48d97c6371/open_data.php on line 20 array ( )
Comments
Post a Comment