What program can I use to rename files with their calculated md5 checksums? GUI or CLI Programs for Linux or Windows or scripts for DOS or the Linux terminal.
Asked
Active
Viewed 3,107 times
1 Answers
1
This will work in Python if it is what you are looking for. It will take and calculate an md5 for a file and then rename the file that sum. Will work on *nix/Windows/?
/usr/bin/env python
import os, hashlib
file = 'path/to/file'
def main():
h = hashlib.md5(file)
output = h.hexdigest()
os.rename( file, output)
if __name__ == '__main__':
main()
Matty
- 324
- 1
- 5
-
-
yes, my mistake the code formating screwed my up, I wrote this in the window, I will make the edit. – Matty Mar 12 '14 at 00:54
-
This would be more useful if it took the path as an argument and performed the operation recursively if the argument was a directory ;) – OregonTrail Mar 12 '14 at 00:58
-
1It would but would not be as simple of an answer. I personally would use BASH for this and take the filename as an arg and search for it with locate -b, calculate a hash with md5sum and the change the name with mv. The OP talked about x-platform so I used Python, Perl scares me. – Matty Mar 12 '14 at 01:05