Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,153,956 members, 7,821,359 topics. Date: Wednesday, 08 May 2024 at 11:54 AM

How Do You Write A Program That Delete Duplicate File On Your System - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / How Do You Write A Program That Delete Duplicate File On Your System (720 Views)

What Can A CS Degree Holder Program that a self-taught cannot do? / Interested In Teaching Yourself Programming? file on link / Java: How Can Write A File on Internet To A SQL Blob Field Directly? (2) (3) (4)

(1) (Reply) (Go Down)

How Do You Write A Program That Delete Duplicate File On Your System by Deicide: 12:06pm On Oct 05, 2022
1. Do you hash all the files
2. Do you delete by name
3 what would be an efficient way to do this
4 what programming language do you think would be best to do this in
5. How would you determine which of the duplicate to keep?

I would love to see you guys solution to the problem any programming language is allowed. If you using Linux and do it using bash more points to you lol grin

No googling am only interested in thought process so exact correctness does not necessarily matter. Good luck.
Re: How Do You Write A Program That Delete Duplicate File On Your System by dplus(m): 1:44pm On Oct 05, 2022
Hello ,

when you mean duplicated files , do you mean the OS allows filename to be same in same directory or different directories , cos I know Windows will not allow same filename in same directory.

If in different directory then , you delete either the old or new one, so date is very critical.

if in different directory then, you have to do a recursive search for each file across all directory,

Any programming language with access to files and directory can do it , C++,C,C#, php, python, java etc

though the OS will also decide choice of programming language
Re: How Do You Write A Program That Delete Duplicate File On Your System by Deicide: 4:47pm On Oct 05, 2022
dplus:
Hello ,

when you mean duplicated files , do you mean the OS allows filename to be same in same directory or different directories , cos I know Windows will not allow same filename in same directory.
I different directory but identical files.
Re: How Do You Write A Program That Delete Duplicate File On Your System by Iambro(m): 5:47pm On Oct 05, 2022
I onced wrote one in PHP
when I wanted to delete over 1k music file that contain around 3-5 duplicates each
it's was fun doing
Check it here https://github.com/iambrojohnson/DuplicateFileRemover
Re: How Do You Write A Program That Delete Duplicate File On Your System by Fourpockets: 6:25pm On Oct 05, 2022
Deicide:
1. Do you hash all the files
2. Do you delete by name
3 what would be an efficient way to do this
4 what programming language do you think would be best to do this in
5. How would you determine which of the duplicate to keep?

I would love to see you guys solution to the problem any programming language is allowed. If you using Linux and do it using bash more points to you lol grin

No googling am only interested in thought process so exact correctness does not necessarily matter. Good luck.
Easy, I could do it with node js file system module plus other modules
You can loop over the directory and find a file "index.js" you then look for an "index-2.js" file or you store the contents in a variable and compare it, delete the second file if they have the same content
Re: How Do You Write A Program That Delete Duplicate File On Your System by Deicide: 7:32pm On Oct 05, 2022
Fourpockets:

Easy, I could do it with node js file system module plus other modules
You can loop over the directory and find a file "index.js" you then look for an "index-2.js" file or you store the contents in a variable and compare it, delete the second file if they have the same content
How would you check for same content?
Re: How Do You Write A Program That Delete Duplicate File On Your System by Deicide: 7:33pm On Oct 05, 2022
Iambro:
I onced wrote one in PHP
when I wanted to delete over 1k music file that contain around 3-5 duplicates each
it's was fun doing
Check it here https://github.com/iambrojohnson/DuplicateFileRemover
How fast was it?
Re: How Do You Write A Program That Delete Duplicate File On Your System by Fourpockets: 7:54pm On Oct 05, 2022
Deicide:
How would you check for same content?
Using the FS module
Re: How Do You Write A Program That Delete Duplicate File On Your System by Iambro(m): 8:05pm On Oct 05, 2022
Deicide:
How fast was it?
depends on the total files.
The program even won phpclass.org 2020 award.
Re: How Do You Write A Program That Delete Duplicate File On Your System by Deicide: 11:19pm On Oct 05, 2022
Iambro:

depends on the total files.
The program even won phpclass.org 2020 award.
Wow that's impressive.
Re: How Do You Write A Program That Delete Duplicate File On Your System by Luckydonalds(m): 7:42am On Oct 06, 2022
I think you have answered your own question. The best way is to hash all the files, this is done recursively from the root directory using a sha1-sum (you could use other hasing algorithms if you like), Linux provides a sha1-sum hash by default, then you loop through all your hashes, if you encounter a duplicate hash, you delete either of them, the date of file creation and filename doesn't matter since the content are the same. All this can be done with a bash script but I'd have to google to come up with a working solution. Even at that, my script might not be efficient because I'm not so versed at bash scripting.
Re: How Do You Write A Program That Delete Duplicate File On Your System by Deicide: 9:35am On Oct 06, 2022
Luckydonalds:
I think you have answered your own question. The best way is to hash all the files, this is done recursively from the root directory using a sha1-sum (you could use other hasing algorithms if you like), Linux provides a sha1-sum hash by default, then you loop through all your hashes, if you encounter a duplicate hash, you delete either of them, the date of file creation and filename doesn't matter since the content are the same. All this can be done with a bash script but I'd have to google to come up with a working solution. Even at that, my script might not be efficient because I'm not so versed at bash scripting.
You could use python though.
Re: How Do You Write A Program That Delete Duplicate File On Your System by dodgelord: 2:08am On Oct 08, 2022
Deicide:
1. Do you hash all the files
2. Do you delete by name
3 what would be an efficient way to do this
4 what programming language do you think would be best to do this in
5. How would you determine which of the duplicate to keep?

I would love to see you guys solution to the problem any programming language is allowed. If you using Linux and do it using bash more points to you lol grin

No googling am only interested in thought process so exact correctness does not necessarily matter. Good luck.

i no sabi o
Re: How Do You Write A Program That Delete Duplicate File On Your System by Deicide: 9:35am On Oct 08, 2022
dodgelord:


i no sabi o
There is a question on leetcode "deleted duplicate" but instead of files you would do it with an array. You could use that to practice.

1 Like

(1) (Reply)

Blockchain Developers, How Much Do You Charge For A Full Application / Help Me With This Javascript Snippet / Let's Embrace Software Engineering Through Scholarship

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 26
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.