In given example, first parameter of Test.dictionnary_files( sourcePath ) is unused, because i did forget to update it after some changes.
Compiler did not complain about it, where he does usually speak a lot and give a lots of good informations.
use System.Security.Cryptography
class Test
def main
source_path = "/home/clement/Projects/test/data"
files_table = .dictionnary_files( source_path )
for file_hash, file_entry in files_table
if file_entry.count > 1
f_path = file_entry[0]
f_count = file_entry.count
print 'File [f_path] appears [f_count]'
def dictionnary_files( sourcePath as String ) as Dictionary<of String, List<of String>>
files = .list_files( "/home/clement/Projects/test/data" )
files_table = Dictionary<of String, List<of String>>()
for file in files
hash_file = .make_hash( file )
tomate as List<of String>?
if files_table.tryGetValue( hash_file, out tomate)
tomate.add( file )
else
tomate_ = [file]
files_table.add( hash_file, tomate_ )
return files_table
def list_files( sourcePath as String ) as String[]?
return Directory.getFiles(sourcePath, "*", SearchOption.AllDirectories)
def make_hash( file as String ) as String
hasher = HashAlgorithm.create("SHA1")
fs = File.openRead( file )
digest = hasher.computeHash(fs)
fs.close
hash = BitConverter.toString(digest)
return hash
> cobra --version
- Code: Select all
2010-10-18 (svn-post-0.8.0)
> mono --version
- Code: Select all
Mono JIT compiler version 2.10.2 (tarball Sat Apr 30 10:15:36 UTC 2011)
Copyright (C) 2002-2011 Novell, Inc and Contributors. http://www.mono-project.com
TLS: __thread
SIGSEGV: altstack
Notifications: epoll
Architecture: x86
Disabled: none
Misc: debugger softdebug
LLVM: supported, not enabled.
GC: Included Boehm (with typed GC and Parallel Mark)
> command-line
- Code: Select all
cobra test.cobra
bye