Published on January 26, 2024By DeveloperBreeze

$directoryPath = '/home/user/projects/using-glob';
$fileExtension = 'jpg';

// View files with the specified extension
foreach (glob($directoryPath . '/*.' . $fileExtension) as $image) {
    echo basename($image) . "\n";
}

// View all files without a specified extension
foreach (glob($directoryPath . '/*') as $file) {
    echo basename($file) . "\n";
}

Comments

Please log in to leave a comment.

Continue Reading:

List Files in a Directory Using os Module

Published on January 26, 2024

python

Batch File Renaming Using os Module

Published on January 26, 2024

python