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.
x
25
25
1
import os
2
import std/sha1
3
import tables
4
5
# Compile: Save as dupes.nim and
6
# compile with: nim compile --opt:speed --run dupes.nim
7
8
echo "Enter search path: "
9
var searchPath: string = readLine(stdin)
10
11
var hashTable = initTable[string, seq[string]]()
12
13
for objPath in walkDirRec(searchPath, {pcFile}):
14
15
var shaResult = $(secureHashFile(objPath))
16
17
if not hashTable.hasKey(shaResult):
18
var matchSeq = newSeq[string]()
19
hashTable[shaResult] = matchSeq
20
21
hashTable[shaResult].add(objPath)
22
23
# Roll through results and print to screen.
24
for key, value in hashTable:
25
echo key, " " ,value
And one of five lights sanded, cleaned, and painted.