比较两个文件夹中的两个文件名

时间:2014-01-30 12:34:49

标签: php

我有两个folder.i总是打印mp3文件夹文件名,但如果图像文件夹与mp3文件具有相同的命名文件,则打印两个名称或没有相同名称然后打印null。

格式如

    mp3/
    image/
mp3   image

1   =  1
2   =  2
3   =  null    

我正在尝试但没有成功

$path = "mp3/";
$ipath = "image/";

if ($handle = opendir($path) && $ihandle = opendir($ipath))
 {
    while (false !== ($file = readdir($handle)) && false !==($ifile = readdir($ihandle)))
     {
        if ('.' === $file && $ifile) continue;
        if ('..' === $file && $ifile) continue;
            //var_dump($file);
                    // do something with the file


                            for($i = 1; $i <= count($file); $i++)
                                {

                                $f=current(explode(".", $file));
                                $f1=current(explode(".", $ifile));
                                if($f==$f1)
                                    {

                                    print''.$f.'='.$f1.'';

                                    }
                                else
                                    {
                                    print''.$f.'='null';

                                    }
                                }




    }
    closedir($handle);
    closedir($ihandle);
}

0 个答案:

没有答案