Duplicate Files Deletor class
This is a topic on Duplicate Files Deletor class within the Programmers Corner forums, part of the Technology category; I recently had many photos duplicated and I was lazy to select each duplicate photo and then delete, so I ...
2Likes
-
2
Post By imported_ksg91
-
Uber Newbie
Duplicate Files Deletor class
I recently had many photos duplicated and I was lazy to select each duplicate photo and then delete, so I wrote a small php class to do the job.
You need to instantiate the class with directory that contain duplicate files and the pattern that is unique to duplicate file.
WARNING: Be careful with duplicate file's pattern if you do not wish to delete important files.
Code:
<?php
/**
*$Author: Ksg91 $
*$Date: 2011-02-27 14:00 +0530 $
*
*This simple class deletes files that has specific sub string in its file name.
*I used it to delete duplicate photos.
*You may edit it as per your need.
*
*WARNING: Be careful while choosing pattern for duplicate files.
* If the pattern you choose is not unique to duplicates, you will
* lose unique and important files.
*/
class DuplicateDelete
{
private $dir,$handle,$dupPattern,$currentFile;
/*constructor to set directory in which files are to be searched and subsring
that a duplicate file will contain. */
function __construct($dir,$dupPattern)
{
$this->dir=$dir;
$this->handle=opendir($dir);
$this->dupPattern=$dupPattern;
}
/*This function will delete all duplicate files*/
function deleteDuplicates()
{
while (false !== ($this->currentFile = readdir($this->handle))) {
if($this->isDuplicate()){
unlink($this->dir."\\".$this->currentFile);
//echo $this->currentFile."
";
}
}
}
/*This function will check if currentFile is duplicate. Returns true if
duplicate, else false. */
function isDuplicate()
{
if(strstr($this->currentFile,$this->dupPattern))
return true;
else
return false;
}
}
/* EXAMPLE */
/* I had photos and videos that were somehow duplicated and all duplicate photos/videos
contained _2 at the end of file. So the substring for those duplicate photos/videos
would be "_2." */
$dd=new DuplicateDelete("E:\\Robo-Opus 11\\New folder\\New folder","_2.");
$dd->deleteDuplicates();
?>
-
Uber Newbie
Re: Duplicate Files Deletor class
awesome!!!!!!!!but still m new to php
-
Uber Newbie
Re: Duplicate Files Deletor class
Thanks buddy I was really looking for this script... it will help me a lot to clean up my mess!

Originally Posted by
imported_ksg91
I recently had many photos duplicated and I was lazy to select each duplicate photo and then delete, so I wrote a small php class to do the job.
You need to instantiate the class with directory that contain duplicate files and the pattern that is unique to duplicate file.
WARNING: Be careful with
duplicate file finder pattern if you do not wish to delete important files.
Code:
<?php
/**
*$Author: Ksg91 $
*$Date: 2011-02-27 14:00 +0530 $
*
*This simple class deletes files that has specific sub string in its file name.
*I used it to delete duplicate photos.
*You may edit it as per your need.
*
*WARNING: Be careful while choosing pattern for duplicate files.
* If the pattern you choose is not unique to duplicates, you will
* lose unique and important files.
*/
class DuplicateDelete
{
private $dir,$handle,$dupPattern,$currentFile;
/*constructor to set directory in which files are to be searched and subsring
that a duplicate file will contain. */
function __construct($dir,$dupPattern)
{
$this->dir=$dir;
$this->handle=opendir($dir);
$this->dupPattern=$dupPattern;
}
/*This function will delete all duplicate files*/
function deleteDuplicates()
{
while (false !== ($this->currentFile = readdir($this->handle))) {
if($this->isDuplicate()){
unlink($this->dir."\\".$this->currentFile);
//echo $this->currentFile."
";
}
}
}
/*This function will check if currentFile is duplicate. Returns true if
duplicate, else false. */
function isDuplicate()
{
if(strstr($this->currentFile,$this->dupPattern))
return true;
else
return false;
}
}
/* EXAMPLE */
/* I had photos and videos that were somehow duplicated and all duplicate photos/videos
contained _2 at the end of file. So the substring for those duplicate photos/videos
would be "_2." */
$dd=new DuplicateDelete("E:\\Robo-Opus 11\\New folder\\New folder","_2.");
$dd->deleteDuplicates();
?>
-
Tech2 Members
Re: Duplicate Files Deletor class
glad you liked it
Similar Threads
-
By raul_8 in forum PC Hardware
Replies: 2
Last Post: 09-29-2006, 01:04 PM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules