jguinch Posted April 28, 2015 Share Posted April 28, 2015 (edited) Ah sorry, i misunderstood.. I thought you wanted to keep at least one file.So it's over complicated to do it with the same method, especially if you want to have a comprehensible code.A good way should be to use _FileListToArray first, then create a 2D array containing the file names and file size. Next, _ArraySort the array by file size, and finally, make a loop in the whole array and FileDelete each file having the same size.Here is an example of what could be done with my previous method, but it will me more complicated to understand than my first code (sorry all, it's a jumble)Local $sPath = "D:\tmp" Local $hSearch = FileFindFirstFile($sPath & "\*.*") If $hSearch = -1 Then Exit Local $sSizes While 1 $sFile = FileFindNextFile($hSearch) If @error Then ExitLoop If @extended Then ContinueLoop $iSize = FileGetSize($sPath & "\" & $sFile) $aDouble = StringRegExp($sSizes, ";([^,]*)," & $iSize & ";", 1) If IsArray($aDouble) Then If $aDouble[0] <> "" Then $sSizes = StringReplace($sSizes, ";" & $aDouble[0] & ",", ";,") ; => FileDelete the first file ConsoleWrite("FileDelete('" & $sPath & "\" & $aDouble[0] & "')" & @CRLF) EndIf ; => FileDelete the next file ConsoleWrite("FileDelete('" & $sPath & "\" & $sFile & "')" & @CRLF) Else $sSizes &= $sFile & "," & $iSize & ";" EndIf WEnd FileClose($hSearch) Edited April 28, 2015 by jguinch Siryx 1 Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
Siryx Posted April 28, 2015 Author Share Posted April 28, 2015 looks more like smileys to me .. holy crap. Link to comment Share on other sites More sharing options...
Siryx Posted April 28, 2015 Author Share Posted April 28, 2015 (edited) I tried it, and it doesn't work.. I will try to make the array thingy now; how do I put the size in the array ? why is there always some 0 in my array which is 3906 ?okay so i found out there is arrayadd and the 0 is the amount of things i got in therearrayadd just adds something to an array, no dimension .. q-qI found the array wiki article, maybe i should have read that.. well, I will tomorrow. thanks for helping me to get so far! Edited April 28, 2015 by Siryx Link to comment Share on other sites More sharing options...
kylomas Posted April 28, 2015 Share Posted April 28, 2015 Siryx, jguinch's example modified slightly. See comments in code...expandcollapse popup#include <array.au3> Local $sPath = "k:\temp" ; path name local $aFiles[10000][2] ; array to hold files col 0 = filename, col 1 = size local $idx = 0 ; index to offset array while processing files Local $hSearch = FileFindFirstFile($sPath & "\*.*") If $hSearch = -1 Then Exit ; find all files in path and populate array with fully qualified name and size While 1 $aFiles[$idx][0] = $sPath & '\' & FileFindNextFile($hSearch) If @error Then ExitLoop If @extended Then ContinueLoop $aFiles[$idx][1] = FileGetSize($aFiles[$idx][0]) $idx += 1 WEnd FileClose($hSearch) ; close search handle redim $aFiles[$idx][2] ; trim array to size actually used (count is in $idx) ; sort by size ascending _arraysort($aFiles,0,0,0,1) _arraydisplay($aFiles) ; iterate array deleting duplicately sized files for $1 = 1 to ubound($aFiles) - 1 if $aFiles[$1][1] = $aFiles[$1-1][1] then ConsoleWrite('delete file = ' & $aFiles[$1][0] & ' size = ' & $aFiles[$1][1] & @CRLF) EndIf nextkylomas Siryx 1 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 Link to comment Share on other sites More sharing options...
Siryx Posted April 29, 2015 Author Share Posted April 29, 2015 Siryx, jguinch's example modified slightly. See comments in code...expandcollapse popup#include <array.au3> Local $sPath = "k:\temp" ; path name local $aFiles[10000][2] ; array to hold files col 0 = filename, col 1 = size local $idx = 0 ; index to offset array while processing files Local $hSearch = FileFindFirstFile($sPath & "\*.*") If $hSearch = -1 Then Exit ; find all files in path and populate array with fully qualified name and size While 1 $aFiles[$idx][0] = $sPath & '\' & FileFindNextFile($hSearch) If @error Then ExitLoop If @extended Then ContinueLoop $aFiles[$idx][1] = FileGetSize($aFiles[$idx][0]) $idx += 1 WEnd FileClose($hSearch) ; close search handle redim $aFiles[$idx][2] ; trim array to size actually used (count is in $idx) ; sort by size ascending _arraysort($aFiles,0,0,0,1) _arraydisplay($aFiles) ; iterate array deleting duplicately sized files for $1 = 1 to ubound($aFiles) - 1 if $aFiles[$1][1] = $aFiles[$1-1][1] then ConsoleWrite('delete file = ' & $aFiles[$1][0] & ' size = ' & $aFiles[$1][1] & @CRLF) EndIf nextkylomasafter the arraydisplay theres nothing going on, no matter what I press. I tried to disable the arraydisplay by;_arraydisplay($aFiles)but it does not delete a file... :/ I still try to figure out how to do array with 2 dimensions..redim $aFiles[$idx][2]this? Link to comment Share on other sites More sharing options...
jguinch Posted April 29, 2015 Share Posted April 29, 2015 Nothing happens because kylomas and I used ConsoleWrite to show the FileDelete step. You have to add the FileDelete line to your code, in place of ConsoleWrite :FileDelete($aFiles[$1][0]) ; for kylomas's code FileDelete($sPath & "\" & $sFile) ; for my code Siryx 1 Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
Siryx Posted April 29, 2015 Author Share Posted April 29, 2015 (edited) Nothing happens because kylomas and I used ConsoleWrite to show the FileDelete step. You have to add the FileDelete line to your code, in place of ConsoleWrite :FileDelete($aFiles[$1][0]) ; for kylomas's code FileDelete($sPath & "\" & $sFile) ; for my code consolewrite doesn't work for me, not in the array tutorials nor here; it's writing nothing anywhere; is that intended?so kylomas code only deletes 2 files and if there are more than 2 it leaves one over (yes my folder is messy af >.<) and i'm trying out yours nowsame... I don't know. So I tried to run them multiple times but yeah then it leaves one over.. maybe I should do it manually ._____.Local $sPath = "D:\Musik - Kopie2" Local $hSearch = FileFindFirstFile($sPath & "\*.*") If $hSearch = -1 Then Exit Local $sSizes While 1 $sFile = FileFindNextFile($hSearch) If @error Then ExitLoop If @extended Then ContinueLoop $iSize = FileGetSize($sPath & "\" & $sFile) $aDouble = StringRegExp($sSizes, ";([^,]*)," & $iSize & ";", 1) If IsArray($aDouble) Then If $aDouble[0] <> "" Then $sSizes = StringReplace($sSizes, ";" & $aDouble[0] & ",", ";,") ; => FileDelete the first file FileDelete($sPath & "\" & $sFile) EndIf ; => FileDelete the next file FileDelete($sPath & "\" & $sFile) Else $sSizes &= $sFile & "," & $iSize & ";" EndIf WEnd FileClose($hSearch)expandcollapse popup#include <array.au3> Local $sPath = "D:\Musik - Kopie2" ; path name local $aFiles[10000][2] ; array to hold files col 0 = filename, col 1 = size local $idx = 0 ; index to offset array while processing files Local $hSearch = FileFindFirstFile($sPath & "\*.*") If $hSearch = -1 Then Exit ; find all files in path and populate array with fully qualified name and size While 1 $aFiles[$idx][0] = $sPath & '\' & FileFindNextFile($hSearch) If @error Then ExitLoop If @extended Then ContinueLoop $aFiles[$idx][1] = FileGetSize($aFiles[$idx][0]) $idx += 1 WEnd FileClose($hSearch) ; close search handle redim $aFiles[$idx][2] ; trim array to size actually used (count is in $idx) ; sort by size ascending _arraysort($aFiles,0,0,0,1) _arraydisplay($aFiles) ; iterate array deleting duplicately sized files for $1 = 1 to ubound($aFiles) - 1 if $aFiles[$1][1] = $aFiles[$1-1][1] then FileDelete($aFiles[$1][0]) EndIf next Edited April 29, 2015 by Siryx Link to comment Share on other sites More sharing options...
Siryx Posted April 29, 2015 Author Share Posted April 29, 2015 (edited) expandcollapse popup#include <array.au3> Local $sPath = "D:\Musik - Kopie2" ; path name Global $aFiles[10000][2] ; array to hold files col 0 = filename, col 1 = size local $idx = 0 ; index to offset array while processing files Local $hSearch = FileFindFirstFile($sPath & "\*.*") If $hSearch = -1 Then Exit ; find all files in path and populate array with fully qualified name and size While 1 $aFiles[$idx][0] = $sPath & '\' & FileFindNextFile($hSearch) If @error Then ExitLoop If @extended Then ContinueLoop $aFiles[$idx][1] = FileGetSize($aFiles[$idx][0]) $idx += 1 WEnd FileClose($hSearch) ; close search handle redim $aFiles[$idx][2] ; trim array to size actually used (count is in $idx) ; sort by size ascending _arraysort($aFiles,0,0,0,1) ; iterate array deleting duplicately sized files for $1 = 1 to ubound($aFiles) - 1 if $aFiles[$1][1] = $aFiles[$1-1][1] then FileDelete($aFiles[$1][0]) FileDelete($aFiles[$1-1][0]) EndIf $aFiles = next would this delete both files $1 and $1-1 which are identical ?€: it worked! - had to delete the$aFiles =though its not even my code but hey Edited April 29, 2015 by Siryx Link to comment Share on other sites More sharing options...
kylomas Posted April 29, 2015 Share Posted April 29, 2015 Siryx, Not sure where you got the$aFiles =from it was not in the code I posted.As far as consolewrite's are concerned. Are you running this code from SciTE?Regarding 2D arrays, look at them like spread sheets. In this case the file name would be in the "A" column and the size would be in the "B" column. AutoIt offsets arrays from 0 so a reference to $aFiles[4][1] will give you the size of the fifth file. In the posted code the loop increment variable ($1) is used to point at the row, the columns are referenced explicitly.The Wiki has several informative tutorials concerning arrays and other AutoIt subjects.kylomas Siryx 1 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 Link to comment Share on other sites More sharing options...
Siryx Posted April 29, 2015 Author Share Posted April 29, 2015 yes I read the article about arrays, thank you and the $aFiles was a leftover from sth I tried earlier. I didnt compile the scripts if you mean that Link to comment Share on other sites More sharing options...
SadBunny Posted April 30, 2015 Share Posted April 30, 2015 Mine is bigger. Roses are FF0000, violets are 0000FF... All my base are belong to you. Link to comment Share on other sites More sharing options...
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