langthang084 Posted September 9, 2014 Posted September 9, 2014 (edited) I have 2 folders, Folder 1 contain 15000 files, Folder 2 contain 2000 files. I want to delete all the files in Folder 1 which has the same name with Folder 2. And here's my code #include <file.au3> $path = "D:\datadic\FOLDER2\" $path2 = "D:\datadic\FOLDER1\" $listLD = _FileListToArray($path, "*.doc", 1, False) $listFull = _FileListToArray($path2, "*.doc", 1, False) for $i = 1 to $listFull[0] for $f = 1 to $listLD[0] ToolTip("Full " & $i & " LD " & $f, 600, 100) if $listLD[$i] = $listFull[$f] Then FileDelete($path2 & $ListFull[$f]) ContinueLoop EndIf Next Next Exit But it tooks so long because of 15000 files in Folder 1 Is there an other way to do this? Thanks all! Edited September 9, 2014 by langthang084
JohnOne Posted September 9, 2014 Posted September 9, 2014 Don't know if Kafu's >SMF duplicate file finder might help you. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
Solution kylomas Posted September 9, 2014 Solution Posted September 9, 2014 (edited) langthang084, Take the tooltip out. The following runs on my slow assed system in appx. 57 seconds... expandcollapse popup#include <FileConstants.au3> #include <File.au3> ;------------------------------------------------------------------------------------------------------------------ ; create files ;------------------------------------------------------------------------------------------------------------------ local $f1 = 'K:\folder1\' local $f2 = 'K:\folder2\' filedelete($f1) filedelete($f2) local $st = timerinit(), $hfl, $idx for $1 = 1 to 15000 $hfl = fileopen($f1 & 'file' & stringformat('%05i',$1) & '.doc',bitor($FO_CREATEPATH, $FO_OVERWRITE)) if $hfl = -1 then exit msgbox(0,'F1 failed','') fileclose($hfl) Next for $1 = 1 to 2000 $idx = stringformat('%05i',random(1,15000,1)) while fileexists($f2 & 'file' & $idx & '.doc') $idx = stringformat('%05i',random(1,15000,1)) wend $hfl = fileopen($f2 & 'file' & $idx & '.doc',bitor($FO_OVERWRITE,$FO_CREATEPATH)) if $hfl = -1 then exit msgbox(0,'F2 failed','') fileclose($hfl) Next ConsoleWrite('Time to create files = ' & stringformat('%4.2f',timerdiff($st)/1000) & ' seconds' & @CRLF) ;------------------------------------------------------------------------------------------------------------------ ; your code modified to run on my system ;------------------------------------------------------------------------------------------------------------------ $st = timerinit() $path = "k:\FOLDER2\" $path2 = "k:\FOLDER1\" $listLD = _FileListToArray($path, "*.doc", 1, False) $listFull = _FileListToArray($path2, "*.doc", 1, False) for $i = 1 to $listFull[0] ; using this for progress instead of tooltip if mod($i,1000) = 0 then ConsoleWrite('Processed ' & stringformat('%05i',$i) & ' files -- time = ' & stringformat('%4.2f',timerdiff($st)/1000) & @CRLF) for $f = 1 to $listLD[0] ; ToolTip("Full " & $i & " LD " & $f, 600, 100) ; if $listLD[$i] = $listFull[$f] Then ; you have the index var reversed causing an array exception if $listLD[$F] = $listFull[$I] Then FileDelete($path2 & $ListFull[$I]) ContinueLoop EndIf Next Next ConsoleWrite('Time to delete duplicate files = ' & stringformat('%4.2f',timerdiff($st)/1000) & @CRLF) Exit Also, see comments in code about your array indexes. kylomas edit: spelling edit2: Using a progress control increased the time appx 2 seconds... expandcollapse popup#include <FileConstants.au3> #include <File.au3> ;------------------------------------------------------------------------------------------------------------------ ; create files ;------------------------------------------------------------------------------------------------------------------ local $f1 = 'K:\folder1\' local $f2 = 'K:\folder2\' filedelete($f1) filedelete($f2) local $st = timerinit(), $hfl, $idx for $1 = 1 to 15000 $hfl = fileopen($f1 & 'file' & stringformat('%05i',$1) & '.doc',bitor($FO_CREATEPATH, $FO_OVERWRITE)) if $hfl = -1 then exit msgbox(0,'F1 failed','') fileclose($hfl) Next for $1 = 1 to 2000 $idx = stringformat('%05i',random(1,15000,1)) while fileexists($f2 & 'file' & $idx & '.doc') $idx = stringformat('%05i',random(1,15000,1)) wend $hfl = fileopen($f2 & 'file' & $idx & '.doc',bitor($FO_OVERWRITE,$FO_CREATEPATH)) if $hfl = -1 then exit msgbox(0,'F2 failed','') fileclose($hfl) Next ConsoleWrite('Time to create files = ' & stringformat('%4.2f',timerdiff($st)/1000) & ' seconds' & @CRLF) ;------------------------------------------------------------------------------------------------------------------ ; your code modified to run on my system ;------------------------------------------------------------------------------------------------------------------ $st = timerinit() progresson('Dups Checker','') $path = "k:\FOLDER2\" $path2 = "k:\FOLDER1\" $listLD = _FileListToArray($path, "*.doc", 1, False) $listFull = _FileListToArray($path2, "*.doc", 1, False) for $i = 1 to $listFull[0] ; using this for progress instead of tooltip if mod($i,1000) = 0 then ConsoleWrite('Processed ' & stringformat('%05i',$i) & ' files -- time = ' & stringformat('%4.2f',timerdiff($st)/1000) & @CRLF) progressset( int(($i/$listfull[0])*100), int(($i/$listfull[0])*100) & '%' ) for $f = 1 to $listLD[0] ; ToolTip("Full " & $i & " LD " & $f, 600, 100) ; if $listLD[$i] = $listFull[$f] Then ; you have the index var reversed causing an array exception if $listLD[$F] = $listFull[$I] Then FileDelete($path2 & $ListFull[$I]) ContinueLoop EndIf Next Next progressoff() ConsoleWrite('Time to delete duplicate files = ' & stringformat('%4.2f',timerdiff($st)/1000) & @CRLF) Exit Edited September 9, 2014 by kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill
langthang084 Posted September 9, 2014 Author Posted September 9, 2014 Yeah! All because of the "Tooltip"
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now