Check the file with the same file name, but a different extension

advertisements

I have a directory contain jpeg and raw image files. Some jpeg files have a raw file version of them, some don't. Luckily, if a jpeg has a raw file they are named the same (excluding the extension). So, I need a way to check this directory for a matching raw file of the same filename, exclusing file extesion. the raw file, file extension could be pretty much anything.

Any ideas how I can do this? I have the filename (excluding extesion) stored of $filename at the moment.

To explain further. I have a directory with the following files in it:

cat.jpg
dog.jpg
bird.jpg
cat.raf
dog.foo

I need to match cat.jpg to cat.rag and dog.jpg to dog.foo. These have just been extracted from a uploaded zip file.


Try searching for files starting with the same name:

$fileWithoutExtension = basename($filename, '.jpg');
$allFilesWithThisName = glob($fileWithoutExtension . '.*');
if (count($allFilesWithThisName)) {
    echo 'There is another file with this name';
}