Wordpress template_directory +路径

I am trying to figure out how to get the name of files in folder, but I can't seem to find a way to point to the right directory

 $location = get_template_directory_uri();
 $dir = $location.'/slider/images/';
 $files2 = scandir($dir, 1);
 print_r($files2) ;

As stated in codex https://developer.wordpress.org/reference/functions/get_template_directory_uri/ the function you used will return theme directory URI. So variable $location contains something like http://example.com/wp-content/themes/theme and that is something that scandir will not accept and understand. You have to replace this for get_template_directory() so $location will contains relative path like wp-content/themes/theme.

You just need to replace first line in your code instead

$location = get_template_directory_uri();

use

$location = get_template_directory();

another function also available in wordpress like.

 <?php $imgaePath = base_url() . 'your_theme_dir/slider/images' 
   echo $imagePath;
 ?>