Trouble in enquing all js files under certain directory

i think you’re putting too many extra bits on the file and path strings.

try this :

function _s_scripts() {
$js_dir = get_template_directory_uri() . "/js/";
foreach(glob($js_dir.'*.*') as $file) {
$label = str_replace(".", "", $file);
wp_enqueue_script($label, $file , array('jquery'), '1.0.0');
}
}
add_action( 'wp_enqueue_scripts', '_s_scripts' );

when I run a similar function locally against a dir, the extra “https://wordpress.stackexchange.com/” and extra “.js” you were adding can causing files to not be found. Also – you added the $js_dir a second time, when $file will already have that information associated to it

edit:

to better explain : $file already had “.js” in its name, when you appended a second “.js” – those files logically do not exist (unless you have naming conventions that were not mentioned.

Also – in $js_dir – you already have the trailing forward slash, but when you try to search for /*.* – thats not a valid pattern so it further confuses glob.

this is at least how I understand it. A test harness I wrote was :

<?php
error_reporting(E_ALL);
error_reporting(-1);
ini_set('error_reporting', E_ALL);
$js_dir = "/Users/MYUSER/Sites/";
$fileglob = glob($js_dir.'*.*');
echo count($fileglob);
foreach( $fileglob as $file) {
    $label = str_replace(".", "", $file);
    echo $file; 
    }
    echo "done";
?>

One more Edit:

To make this a better search, instead of *.* do this :
….

foreach(glob($js_dir.'*.js') as $file) {

that way, if you have other, system files (like thumbnail icons, text files, etc.. ) they don’t get gathered up with the glob