Jump to content

Repporting duplicated files


Recommended Posts

Hi everyone!

I'm trying to clean duplicated files with different attributes, except size and extention. What I've done in the appended code is to :

1) get the user to input the file extention (this can easily be improved).

2) Autoit Runwaits Dir from command prompt and creates a list of files to compare (could also have used FileFindFirstFile).

3) Autit runwaits FC.Exe to binary compare the files.

4) If there´s a binary match then file path and name are appended to a text file. (this needs cleaning up as repetitions occur).

Watch out for line 82, you need to replace the spanish text FC.EXE returns if there´s a binary match for your OS language equivalent.

PROBLEM 2):

The script works fine for a small amount of dummy short txt files, but gets stuck with larger (i.e. pdf) files

#include <File.au3>
Global $FileType
Global $NumFiles
Global $Separator="--*--"
Global $FileNum
Global $NameSize
Global $NameFile
Extension(); Enter file extension
EvalExt(); Evaluates whether the extension is valid
Reporter(); Generates a file report to "Report.txt" starting form script directory
ReportNumFiles(); Number of lines in report
Sizer(); Generates a file size report to "Size.txt" starting form script directory
Equal()
Exit

Func Extension(); Ingreso de extensión
    $FileType= InputBox("Extention", "Enter extention (3 chars & no wildcards)", "", "", -1, -1, 0, 0)
EndFunc

Func EvalExt();  Evaluates whether the extension is valid
    Local $TypeLength=StringLen ($FileType)
    While $TypeLength<>3 
  $FileType= InputBox("Extention", "Enter filetype (3 chars only)", "", "", -1, -1, 0, 0)
    Wend
    While StringInStr($FileType, "*")<>0 
  $FileType= InputBox("Extention", "Enter extension, no wildcards", "", "", -1, -1, 0, 0)
    Wend
EndFunc

Func Reporter(); Generates a file report to "Report.txt" starting form script directory
    RunWait(@ComSpec & " /c dir *." &$FileType &" /OSG /S /B>Report.txt")
EndFunc

Func ReportNumFiles(); Number of lines in report
    $NumFiles=_FileCountLines("Report.txt")
EndFunc

Func Sizer(); Generates a file size report to "Size.txt" starting form script directory
    Local $TempSize
    For $TempSize=1 to $NumFiles step 1
  $Sizer=FileReadLine("Report.txt", $TempSize)
  $Sizer1=FileGetSize($Sizer)
  FileWriteLine("Size.txt", $Sizer1)
    Next
EndFunc

Func Equal()
    For $FileNum=1 to $NumFiles step 1
  Step1Comp(); Appends file to compare and comparison separation header
  Comparer(); File compared
    Next
EndFunc
    
Func Step1Comp(); Appends file to compare and comparison separation header
    FileWriteLine("Equal.txt", $Separator &$Separator &$Separator)
    $NameFile=FileReadLine("Report.txt", $FileNum)
    FileWriteLine("Equal.txt", $NameFile)
    $NameSize=FileReadLine("Size.txt", $FileNum)
    FileWriteLine("Equal.txt", $Separator)
EndFunc
    
Func Comparer()
Local $Filer
Local $CompSize
Local $Compared
Local $Complines
  For $Filer=($FileNum +1) to $NumFiles Step 1
     $CompSize=FileReadLine("Size.txt", $Filer)
     $Compared=FileReadLine("Report.txt", $Filer)

     If FileExists("comparison.txt") then
     FileDelete("comparison.txt")
     Endif
     
     If $CompSize==$NameSize then
    RunWait(@ComSpec & " /c FC /B " &$NameFile &" " &$Compared &">comparison.txt")  
    Sleep(1000)
     Endif

     $text=FileReadLine("comparison.txt", 2)
     
     If $text=="FC: no se han encontrado diferencias" then
     FileWriteLine("Equal.txt", $Compared)
     Endif
  Next
EndFunc
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...