开发者

Check for file with same filename, but different extension

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开发者_Python百科 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';
}


As you already have the filename w/o the extension, you can just check if the raw file exists (file_exists()):

   if (file_exists($filename.'.raw')) {
     echo 'RAW file exists:', $filename , "\n";
   }

But this seems so trivial to me, that I might did not understood your question completely.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜