Hirdetés

Keresés

Új hozzászólás Aktív témák

  • Jim-Y

    veterán

    válasz Karma #6413 üzenetére

    Közben próbálkoztam 1-2 dologgal

    1: az eredeti
    $loc = get-location
    $files = get-childitem -Path $loc -Recurse | where {$_.Length -gt 0}
    $length = $files.length
    $multiples = @()
    $rows = 0
    $groups = 0
    [int]$10n = $length*0.1
    [int]$20n = $length*0.2
    [int]$30n = $length*0.3
    [int]$40n = $length*0.4
    [int]$50n = $length*0.5
    [int]$60n = $length*0.6
    [int]$70n = $length*0.7
    [int]$80n = $length*0.8
    [int]$90n = $length*0.9
    [int]$100n = $length
    for($i=0;$i -lt $length;++$i){
    $ismultiple = 0
    $tempi = $files[$i]
    switch($i)
    {
    $10n { write-host "10%" }
    $20n { write-host "20%" }
    $30n { write-host "30%" }
    $40n { write-host "40%" }
    $50n { write-host "50%" }
    $60n { write-host "60%" }
    $70n { write-host "70%" }
    $80n { write-host "80%" }
    $90n { write-host "90%" }
    $100n { write-host "100%" }
    }
    if($multiples -contains $tempi.FullName){ } else {
    for($j=$i+1;$j -lt $length;++$j){
    $tempj = $files[$j]
    if($tempj.Name -eq $tempi.Name -and $tempj.Length -eq $tempi.Length){
    $multiples += $tempj.FullName
    $rows++
    $ismultiple = 1
    }
    }
    if($ismultiple){
    $multiples += $tempi.FullName
    $rows++
    $groups++
    $multiples += "`n"
    }
    }
    }
    $multiples += "$loc folder has $length files, there are $groups files multiplied,`n and you could delete $($rows-$groups) files from the $rows multiplications!"
    $multiples > multiples.txt

    Ez a tesztmappán ~21-22mp-ig futott

    2: nem tömbbe írós, hanem fileba:

    Ebben a verzióban a $multiples tömb helyett amit a végén fájlba írok, egy fájlhozz appendelem szekvenciálisan a dolgokat
    $multiples = @() -> New-Item multiples.txt -type file -force
    $multiples += $files[$j].FullName ->
    Add-Content multiples.txt -value $files[$j].FullName
    stb..

    Ez a tesztmappán 1-2mp-el futott hosszabb ideig mint az első

    3: hashmap
    Sajnos nem sikerült olyan sszociatív tömböt csinálnom ahol a key-nek megette volna a fájl nevét :( Így egy .NET-es ArrayList-el próbálkoztam. Sajnos ez fut legtovább, a tesztmappán olyan 24mp-ig..

    $loc = get-location
    $hashTable = New-Object System.Collections.ArrayList(,(get-childitem -Path $loc -Recurse | where {$_.Length -gt 0}))
    $duplications = New-Object System.Collections.ArrayList($null)
    $rows = 0
    $groups = 0
    $length = $hashTable.Count
    for($i=0;$i -lt $length;++$i){
    $ism = 0
    if($duplications.Contains($hashTable.Item($i).FullName)){ } else {
    $temp = $hashTable.Item($i)
    for($j=$i+1;$j -lt $length;++$j){
    $tempj = $hashTable.Item($j)
    if($tempj.Name -eq $temp.Name -and $tempj.Length -eq $temp.Length){
    $duplications.Add($tempj.FullName)
    $rows++
    $ism = 1
    }
    }
    if($ism) {
    $rows++
    $groups++
    $duplications.Add($temp.FullName)
    $duplications.Add("`n")
    }
    }
    }
    Write-Host "$length files, there are $groups files multiplied,`n and you could delete $($rows-$groups) files from the $rows multiplications!"
    $duplications > multiples.txt

    Most véletlenül az egész partíció gyökerére futtattam le az első verziót, 10perc alatt csinált meg 10%-ot :D

Új hozzászólás Aktív témák