Jul
22
2017
记一次面试题(用PHP写一个检测重复文件的脚本)
大概的题目意思是利用PHP写一个脚本,调用如:
php.exe shell.php ./tmp ./dir/123
返回结果如:
123.php 222.php ------------ 22.abc 3.xml ------------
我的代码:
<?php unset($argv[0]); foreach ($argv as $v) { $arr=[]; $path=__dir__.'/'.$v.'/'; if(is_dir($v)){ $f=scandir($v); foreach($f as $w){ if(is_file($path.$w)){ $arr[md5_file($path.$w)][]=$w; } } foreach ($arr as $z) { if(count($z)>1){ foreach ($z as $x) { echo $x."\n"; } } } echo "----------\n"; } }
发表评论: