DonationCoder.com forum
 
Read-only archive. This is a static copy of the DonationCoder.com forum. Reading and searching work as before; logging in, posting and private messages do not.
Archive of 2026-10-21 · About this archive · Main site

Author Topic: DONE: HashReplace - Replace all files with identical contents  (Read 22,051 times)

justice

  • Solve issues simply.
  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,898
    • Participated in NANY Challenge Four Times
    • Cody Award
    • Coding Snacks
    • DJ Badge - DJ
What it does:
Replace all files in a folder with identical filename AND SHA1 hash as original.file with new.file.

Use Cases
Say I have updated the contents of a php file that is used multiple times throughout my project, and now I want all other copies of that file to be updated as well.
In most cases the following code would work:
Code: (generic)
replace some_file.php c:\projects\example_project
However if the file is readme.txt or config.php for example, then you'd have overwritten many wrong copies. Using HashReplace only files with the same name and same contents will be overwritten with the new contents.

Download
Source, Executable and Test files
« Last Edit: June 15, 2011, 12:47 PM by justice »

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,931
    • Gathering Badge
    • Plugin Coding Medal
    • Participated in NANY Challenge Seventeen Times
    • Cody Award
    • Coding Snacks
    • Volunteers/Staff
Re: DONE: HashReplace - Replace all files with identical contents
« Reply #1 on: June 15, 2011, 03:26 PM »
very nice idea!

justice

  • Solve issues simply.
  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,898
    • Participated in NANY Challenge Four Times
    • Cody Award
    • Coding Snacks
    • DJ Badge - DJ
Re: DONE: HashReplace - Replace all files with identical contents
« Reply #2 on: June 26, 2012, 12:16 PM »
If you want to play with the latest source, you can now fork from Bitbucket:
https://bitbucket.org/svandragt/hashreplace

I'll keep posting executable releases in this topic when they're available.

david842

  • Member
  • Joined in 2016
  • **
  • Posts: 7
Re: DONE: HashReplace - Replace all files with identical contents
« Reply #3 on: February 02, 2019, 04:47 PM »
In most file systems, you cannot have two or more files with the same filename in the same directory. So, I assume the problem description should specify that the replacements get done in the files of a given directory and its subdirectories.

Original address: https://www.donationcoder.com/forum/index.php?topic=27061.0