Sign in to follow this  
Followers 0
asgarcymed

Does AutoIt have something built-in like Dictionary Object?

13 posts in this topic

When using Windows Script Host, we can use the "Dictionary Object"...

«

Set dict = CreateObject("Scripting.Dictionary")

»

Does AutoIt have something built-in like Dictionary Object? Or it is obligatory to use the "Dictionary Object", via ObjCreate?

Thanks.

Regards.


MLMK - my blogging craziness...

Share this post


Link to post
Share on other sites



Afraid not, you either have to use the Scripting.Dictionary object and use it, or create your own set of functions. I opted to create my own, due to some computers I run scripts on not having that object (Wine is good, but not that good). I'm not home now to post what I have, but if you don't have to worry about that, go for the COM object. Search around, there are some functions on the boards to help you out with them, made my GaryFrost if I remember right.

Share this post


Link to post
Share on other sites

When it becomes possible to you, please, post what you have...

:P

Thanks.

Regards.


MLMK - my blogging craziness...

Share this post


Link to post
Share on other sites

Share this post


Link to post
Share on other sites

Made it home, posting the file now. Function names are the same as Gary's he linked to, just with an additional beginning parameter on each (the actual object to be acted on). Used to have both methods in the function calls (Scripting.Object, and mine), but it kept messing up, so I took out the Scripting Object method to test mine out. Works well.

Dictionary.au3

Share this post


Link to post
Share on other sites

ptrex - Why am I looking for the dictionary functionality ? - please look at:

http://www.autoitscript.com/forum/index.ph...c=57778&hl=

I am trying to make an AutoIt script able to search for true duplicate files (same SIZE + same MD5 HASH/CHECKSUM), and after deleting clones...

Since nobody has help me here, I asked for help in VBS Forums, and everybody said to use the "Dictionary Object" in order to detect repeated file's size and md5...

Thank you, to all you, for replying to this topic!!! :P

PS - If you want to help about the creation of an AutoIt script able to search for true duplicate files (same SIZE + same MD5 HASH/CHECKSUM), and after deleting clones; your help will be welcome!!!!

I am still confused and doubtful...

Thanks.

Regards.


MLMK - my blogging craziness...

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

Hi,

My func for removing the dupes may be a starting point, then look up the other file specs and how to get them?....

Best, randall

[PS This is part of the filelisttoarraynew in link in my signature..]

Func _ArrayDeleteDupes(ByRef $arrItems)
    If @OSTYPE = "WIN32_WINDOWS"  Then Return 0
    Local $i = 0, $objDictionary = ObjCreate("Scripting.Dictionary")
    For $strItem In $arrItems
        If Not $objDictionary.Exists ($strItem) Then
            $objDictionary.Add ($strItem, $strItem)
        EndIf
    Next
    ReDim $arrItems[$objDictionary.Count ]
    For $strKey In $objDictionary.Keys
        $arrItems[$i] = $strKey
        $i += 1
    Next
    $arrItems[0 ]=$objDictionary.Count -1
    Return 1
EndFunc   ;==>_ArrayDeleteDupes
Edited by randallc

Share this post


Link to post
Share on other sites

randallc - you have "the gold" I was looking for! :P

Could you please post an example/sample (AU3 code) how to use your function [from: $target-path = InputBox ("Target Path...", "What is the target path to detect and delete duplicate files?")]?

Thanks.

Regards.


MLMK - my blogging craziness...

Share this post


Link to post
Share on other sites

Hi,

Did you already look at the examples in the zip from the link in my sig?

If they don't help, you'll need to explain more clearly what you want..

Are the duplicated files ;

1. In the same directory?

2. In a number of subdirectories with the same name/ different anmes?

Best, Randall

Share this post


Link to post
Share on other sites

*) There are different main paths which may have dupes; for example:

$path1 = "C:\Main"

$path2 = "D:\Main"

$path3 = "E:\Main"

*) I need to define "inclusion and/or exclusion filters"; for example (search only for *.pdf and *.chm files; or, search *.* except *.doc).

*) I would like to create an "automatically delete" method, by previously defining "automatic deletion rules":

First rule => Whenever possible, delete all dupes located at any path except my preferred path ($path1)...

Second rule =>

If dupes exist exactly inside my preferred path ($path1), then delete the dupes which have shorter filename length (StringLen).

If dupes are exactly inside my preferred path ($path1) and have the same filename length, then delete the dupes which newer file's creation date (analyze: year, month, day, hour, minute, second).

What is a dupe (duplicate file)? It may be:

*) "Perfect/true duplicate" => same size (bytes) + same hash/checksum (as md5 or sha1)

*) "Not sure however highly probable dupes" => same size (bytes) + same name

*) "Doubtful however probable dupes" => approximately same size + approximately same name

(approximately same size means: size(file1) = size(file2) + or - 100 bytes)

(approximately same name means:

First => analyze all filename's string

Second => use StringSplit to try to isolate "words" (delimiters: space bar, comma, semicolon, dot) (exclude the final dot + extension; for example, exclude: ().pdf)

Third => analyze filename's string fragments/splits/words, and if many of them are equal, file are very related.

For example:

"Java for Dummies - CRC Press.pdf" and "CRC Press- Java for Dummies.pdf"

This is what I dream with...

However I need help; my knowledge needs to be improved in order to be able to do that...

Hope and thank for your help :P

Best regards.


MLMK - my blogging craziness...

Share this post


Link to post
Share on other sites

I tried, as strategy: use, as dictionary's keys, the combination of [$size & $md5].

As dictionary's items, I use Full Path (which, of course, includes the name of each file).

I tried to use the dictionary's "Exists" method, which checks and does not allow 2 keys to be equal. Thus, if a true duplicate file exists, the keys (combination of [$size & $md5]) would be equal... This is the way how to "hunt"/"catch" the true duplicate files...

In theory, I think I am correct; however, in practice I am making something wrong, because my script never catches true duplicate files (and I voluntary copied the same file many times; just to test/debug my script)...

Here it is:

#Include <File.au3>
#Include <Array.au3>

$path = "L:\mais eBooks\0000\TESTES"
$files_list_array = _FileListToArray($path, "*.*")

For $n = 1 To $files_list_array[0]
   
    $file_size_bytes = FileGetSize($path & "\" & $files_list_array[$n])

    $md5_object = ObjCreate("XStandard.MD5") ; "ActiveX=COM Component to easily get MD5 Hash/CheckSum
    ; It is FreeWare!!!... If interested, look at:
    ; http://www.xstandard.com/en/documentation/xmd5/

    $md5_hash = $md5_object.GetCheckSumFromFile ($path & "\" & $files_list_array[$n])

    $dict = ObjCreate("Scripting.Dictionary")
   
    $dict.CompareMode = 1 ; "Text Mode"

    $dict_key = $file_size_bytes & $md5_hash

    $dict_item = $path & "\" & $files_list_array[$n]

    If Not $dict.Exists ($dict_key) Then
        $dict.Add ($dict_key, $dict_item)
       
        ; MsgBox (0, "", $dict_key & Chr(13) & $dict_item)
       
    ElseIf $dict.Exists ($dict_key) Then
        FileWrite(@DesktopDir & "\Dupes.csv", $dict_item & "," & $dict_key & Chr(13))
    EndIf
   
Next

Can you please help me to correct/debug this script?

Thanks.

Regards.


MLMK - my blogging craziness...

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0