I was wanting to spend some time with Nim programming language since it looks very similar to two of my favorite languages, Python being one. I am very impressed with it so far but I don’t really have anything to write at the moment and the kid keeps bugging me to paint his traffic light so why not something quick and easy? SHA is slow.
I will be using this language a lot so I’ll post more as I do more. I plan to tackle GUI stuff soon.
import os
import std/sha1
import tables
# Compile: Save as dupes.nim and
# compile with: nim compile --opt:speed --run dupes.nim
echo "Enter search path: "
var searchPath: string = readLine(stdin)
var hashTable = initTable[string, seq[string]]()
for objPath in walkDirRec(searchPath, {pcFile}):
var shaResult = $(secureHashFile(objPath))
if not hashTable.hasKey(shaResult):
var matchSeq = newSeq[string]()
hashTable[shaResult] = matchSeq
hashTable[shaResult].add(objPath)
# Roll through results and print to screen.
for key, value in hashTable:
echo key, " " ,valueAnd one of five lights sanded, cleaned, and painted.