Skip to content

Instantly share code, notes, and snippets.

@wolffc
Last active August 29, 2015 14:21
Show Gist options
  • Save wolffc/50b42eb086fd8b100e8c to your computer and use it in GitHub Desktop.
Save wolffc/50b42eb086fd8b100e8c to your computer and use it in GitHub Desktop.
find dublicate files in the current directory using md5 hashes
<?php
$data = array();
$directoryHandle = dir(__DIR__);
$path = $directoryHandle->path .'/';
while (false !== ($entry = $directoryHandle->read())) {
if(is_file($path.$entry) && substr($entry, 0) !== '.'){
$hash = md5_file($path.$entry);
$data[$hash][] = $path.$entry;
}
}
foreach ($data as $hash=>$files) {
if (count($files) >1){
echo ' '. $hash . PHP_EOL;
foreach($files as $f){
echo ' ' .$f . PHP_EOL;
}
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment