Skip to content

Commit 1fad716

Browse files
authored
Merge pull request #290 from Tejas1510/duplicate
Added the code for Duplicate File Remover
2 parents c7f0b69 + cb256c4 commit 1fad716

File tree

3 files changed

+68
-0
lines changed

3 files changed

+68
-0
lines changed

Java/DuplicateFileRemover/Readme.MD

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Duplicate File Remover
2+
3+
## Introduction
4+
```
5+
It is a simple java code which help to delete all the duplicate file from a user specified Directory
6+
```
7+
## How to use the code
8+
```
9+
1. Download the given code
10+
2. Run the duplicate.java file
11+
3. Enter the path of your Folder
12+
3. All Duplicate files will be removed
13+
```
14+
## Output
15+
16+
![endpoint](https://github.com/Tejas1510/hacking-tools-scripts/blob/duplicate/Java/DuplicateFileRemover/images/image1.png)
17+
18+
![built with love](https://forthebadge.com/images/badges/built-with-love.svg)
19+
20+
Check out my Github profile [Tejas1510!](https://github.com/Tejas1510)
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package FileCounter;
2+
import java.io.BufferedReader;
3+
import java.io.File;
4+
import java.io.FileReader;
5+
import java.util.*;
6+
public class duplicate {
7+
public static int countDirectory=0;
8+
public static void removeduplicate(File directory) throws Exception{
9+
ArrayList<String> fileList = new ArrayList<>();
10+
11+
for (File file : directory.listFiles()) {
12+
File file1 = new File(file.getAbsolutePath());
13+
FileReader fr = new FileReader(file1);
14+
BufferedReader reader = new BufferedReader(fr);
15+
StringBuilder stringBuilder = new StringBuilder();
16+
String line = null;
17+
String ls = System.getProperty("line.separator");
18+
while ((line = reader.readLine()) != null) {
19+
stringBuilder.append(line);
20+
stringBuilder.append(ls);
21+
}
22+
stringBuilder.deleteCharAt(stringBuilder.length() - 1);
23+
String content = stringBuilder.toString();
24+
25+
if(fileList.contains(content)) {
26+
System.out.println("The file "+ file.getName()+" is a duplicate file");
27+
System.out.println(file.getName()+ " Removed");
28+
file1.delete();
29+
System.out.println("");
30+
}
31+
else {
32+
fileList.add(content);
33+
}
34+
reader.close();
35+
36+
}
37+
38+
}
39+
public static void main(String args[]) throws Exception {
40+
Scanner s = new Scanner(System.in);
41+
System.out.println("Enter the Path of your directory : ");
42+
String path = s.next();
43+
File file = new File(path);
44+
duplicate.removeduplicate(file);
45+
System.out.println("All Duplicates File Removed");
46+
s.close();
47+
}
48+
}
162 KB
Loading

0 commit comments

Comments
 (0)