DonationCoder.com forum
 
Read-only archive. This is a static copy of the DonationCoder.com forum. Reading and searching work as before; logging in, posting and private messages do not.
Archive of 2026-10-21 · About this archive · Main site

Author Topic: FindZipFilenameAndFolder.zip & FindZipFilenameAndFolder Folder Finder  (Read 5,638 times)

CodeTRUCKER

  • Bush Flying... where I'd rather be.
  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,086
    • Participated in NANY Challenge Once
    • Military Service Badge - US Navy
No that is not the latest lousy cryptogram. It is kind of a description of what I am looking for.

Here's the deal... I have amassed a huge number (1+TBs) of archive files (zip, rar, 7z, etc.) which I expanded into folders, but failed to properly delete the temporary folders of the same names. Each time I upgraded my offline storage and computers I always said to myself I'd clean up the mess later. Well, I didn't and it's some years since 1996. Yeah, I know a bunch of them won't even work these days, but that is beside the point.

Can anyone direct me to a special duplicate file/folder finder which will ignore the extension? One which will find the folder name which matches the archive name? Once I can make sure I have the archive file then I can delete the expanded folder. I'm anticipating it will reduce my volume by 60-80 percent (best guess) which will also greatly reduce my disk maintenance and defrag time.

Any ideas?

Thanks for reading. :)
Calvin

DISCLAIMER - I have made and make many threads for questions and even project posts across the Internet. Unfortunately, many are in limbo because I cannot remember where they are at. If anyone knows of an open thread or an unanswered inquiry, please PM me. Thank you.
   
Notice: Unless stated otherwise, I receive no compensation for anything I post here.

4wd

  • Pedantic Old Bastard
  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 5,652
    • Coding Snacks
PowerShell script: ArcDirMatcher.ps1

2019-01-24 11_48_11-ArcDirMatcher.png

As you can see, rather simple.

It outputs to a text file in the archive folder, (ArcDirMatcher.txt), that can be easily edited to a command file and then run to remove the folders.

Sample Output
Rem -- Replace 'Matches:' with 'rmdir /s /q' in a text editor,
Rem -- then rename the extension from '.txt' to '.cmd'
Rem -- and run it to remove folders.

Rem Match 1: D:\Downloads\Books\9781783551712-LEARNING_PYTHON_Code.zip
Matches: "K:\Test\9781783551712-LEARNING_PYTHON_Code"

Rem Match 2: D:\Downloads\Books\9781783552016-MASTERING_SOCIAL_MEDIA_MINING_WITH_PYTHON_Code.zip
Matches: "K:\Test\9781783552016-MASTERING_SOCIAL_MEDIA_MINING_WITH_PYTHON_Code"

Rem Match 3: D:\Downloads\Books\9781783555130-PYTHON_MACHINE_LEARNING_code.zip
Matches: "K:\Test\9781783555130-PYTHON_MACHINE_LEARNING_code"

Rem Match 4: D:\Downloads\Books\9781783980420-PYTHON_FOR_SECRET_AGENTS_code.zip
Matches: "K:\Test\9781783980420-PYTHON_FOR_SECRET_AGENTS_code"

Rem Match 5: D:\Downloads\Books\9781784393878-PANDAS_COOKBOOK_Code.zip
Matches: "K:\Test\9781784393878-PANDAS_COOKBOOK_Code"

Rem Match 6: D:\Downloads\Books\9781785280009-LINUX_DEVICE_DRIVERS_DEVELOPMENT_Code.zip
Matches: "K:\Test\9781785280009-LINUX_DEVICE_DRIVERS_DEVELOPMENT_Code"

Rem Match 7: D:\Downloads\Books\9781785281655-DOCKER_ON_WINDOWS_Code.zip
Matches: "K:\Test\9781785281655-DOCKER_ON_WINDOWS_Code"

Rem Match 8: D:\Downloads\Books\9781785289729-MASTERING_PYTHON_Code.zip
Matches: "K:\Test\9781785289729-MASTERING_PYTHON_Code"

Rem Match 9: D:\Downloads\Books\9781785883804-BAYESIAN_ANALYSIS_WITH_PYTHON_Code.zip
Matches: "K:\Test\9781785883804-BAYESIAN_ANALYSIS_WITH_PYTHON_Code"

Rem Match 10: D:\Downloads\Books\9781785885587-NODEJS_DESIGN_PATTERNS_SECOND_EDITION_Code.zip
Matches: "K:\Test\9781785885587-NODEJS_DESIGN_PATTERNS_SECOND_EDITION_Code"

Rem Match 11: D:\Downloads\Books\9781785889622-MACHINE_LEARNING_ALGORITHMS_Code.zip
Matches: "K:\Test\9781785889622-MACHINE_LEARNING_ALGORITHMS_Code"

Rem Match 12: D:\Downloads\Books\9781786462169-TENSORFLOW_MACHINE_LEARNING_COOKBOOK_Code.zip
Matches: "K:\Test\9781786462169-TENSORFLOW_MACHINE_LEARNING_COOKBOOK_Code"

Rem Match 13: D:\Downloads\Books\9781786466204-GO_DESIGN_PATTERNS_Code.zip
Matches: "K:\Test\9781786466204-GO_DESIGN_PATTERNS_Code"

Rem Match 14: D:\Downloads\Books\9781786467171-MASTERING_OPENCV_3_SECOND_EDITION_Code.zip
Matches: "K:\Test\9781786467171-MASTERING_OPENCV_3_SECOND_EDITION_Code"

Rem Match 15: D:\Downloads\Books\9781787121706-MASTERING_C_MULTITHREADING_Code.zip
Matches: "K:\Test\9781787121706-MASTERING_C_MULTITHREADING_Code"

Rem Match 16: D:\Downloads\Books\9781787125445-MASTERING_BLOCKCHAIN_Code.zip
Matches: "K:\Test\9781787125445-MASTERING_BLOCKCHAIN_Code"

Rem Match 17: D:\Downloads\Books\9781787125643-GO_SYSTEMS_PROGRAMMING_Code.zip
Matches: "K:\Test\9781787125643-GO_SYSTEMS_PROGRAMMING_Code"

Rem Match 18: D:\Downloads\Books\9781787282049-PERL_6_DEEP_DIVE_Code.zip
Matches: "K:\Test\9781787282049-PERL_6_DEEP_DIVE_Code"

Rem Match 19: D:\Downloads\Books\9781788290142-MICROSOFT_POWER_BI_COOKBOOK_Code.zip
Matches: "K:\Test\9781788290142-MICROSOFT_POWER_BI_COOKBOOK_Code"

Rem Match 20: D:\Downloads\Books\9781788393850-ARCHITECTING_MODERN_JAVA_EE_APPLICATIONS_Code.zip
Matches: "K:\Test\9781788393850-ARCHITECTING_MODERN_JAVA_EE_APPLICATIONS_Code"

Rem Match 21: D:\Downloads\Books\9781788396646-DEVOPS_WITH_KUBERNETES_Code.zip
Matches: "K:\Test\9781788396646-DEVOPS_WITH_KUBERNETES_Code"

Rem Match 22: D:\Downloads\Books\Mastering Docker 2nd Edition_Code.zip
Matches: "K:\Test\Mastering Docker 2nd Edition_Code"

Rem Match 23: D:\Downloads\Books\Raspberry Pi Cookbook for Python Programmers - Code.zip
Matches: "K:\Test\Raspberry Pi Cookbook for Python Programmers - Code"

ArcDirMatcher.cmd after editing above output
Rem -- Replace 'Matches:' with 'rmdir /s /q' in a text editor,
Rem -- then rename the extension from '.txt' to '.cmd'
Rem -- and run it to remove folders.

Rem Match 1: D:\Downloads\Books\9781783551712-LEARNING_PYTHON_Code.zip
rmdir /s /q "K:\Test\9781783551712-LEARNING_PYTHON_Code"

Rem Match 2: D:\Downloads\Books\9781783552016-MASTERING_SOCIAL_MEDIA_MINING_WITH_PYTHON_Code.zip
rmdir /s /q "K:\Test\9781783552016-MASTERING_SOCIAL_MEDIA_MINING_WITH_PYTHON_Code"

Rem Match 3: D:\Downloads\Books\9781783555130-PYTHON_MACHINE_LEARNING_code.zip
rmdir /s /q "K:\Test\9781783555130-PYTHON_MACHINE_LEARNING_code"

Rem Match 4: D:\Downloads\Books\9781783980420-PYTHON_FOR_SECRET_AGENTS_code.zip
rmdir /s /q "K:\Test\9781783980420-PYTHON_FOR_SECRET_AGENTS_code"

Rem Match 5: D:\Downloads\Books\9781784393878-PANDAS_COOKBOOK_Code.zip
rmdir /s /q "K:\Test\9781784393878-PANDAS_COOKBOOK_Code"

Rem Match 6: D:\Downloads\Books\9781785280009-LINUX_DEVICE_DRIVERS_DEVELOPMENT_Code.zip
rmdir /s /q "K:\Test\9781785280009-LINUX_DEVICE_DRIVERS_DEVELOPMENT_Code"

Rem Match 7: D:\Downloads\Books\9781785281655-DOCKER_ON_WINDOWS_Code.zip
rmdir /s /q "K:\Test\9781785281655-DOCKER_ON_WINDOWS_Code"

Rem Match 8: D:\Downloads\Books\9781785289729-MASTERING_PYTHON_Code.zip
rmdir /s /q "K:\Test\9781785289729-MASTERING_PYTHON_Code"

Rem Match 9: D:\Downloads\Books\9781785883804-BAYESIAN_ANALYSIS_WITH_PYTHON_Code.zip
rmdir /s /q "K:\Test\9781785883804-BAYESIAN_ANALYSIS_WITH_PYTHON_Code"

Rem Match 10: D:\Downloads\Books\9781785885587-NODEJS_DESIGN_PATTERNS_SECOND_EDITION_Code.zip
rmdir /s /q "K:\Test\9781785885587-NODEJS_DESIGN_PATTERNS_SECOND_EDITION_Code"

Rem Match 11: D:\Downloads\Books\9781785889622-MACHINE_LEARNING_ALGORITHMS_Code.zip
rmdir /s /q "K:\Test\9781785889622-MACHINE_LEARNING_ALGORITHMS_Code"

Rem Match 12: D:\Downloads\Books\9781786462169-TENSORFLOW_MACHINE_LEARNING_COOKBOOK_Code.zip
rmdir /s /q "K:\Test\9781786462169-TENSORFLOW_MACHINE_LEARNING_COOKBOOK_Code"

Rem Match 13: D:\Downloads\Books\9781786466204-GO_DESIGN_PATTERNS_Code.zip
rmdir /s /q "K:\Test\9781786466204-GO_DESIGN_PATTERNS_Code"

Rem Match 14: D:\Downloads\Books\9781786467171-MASTERING_OPENCV_3_SECOND_EDITION_Code.zip
rmdir /s /q "K:\Test\9781786467171-MASTERING_OPENCV_3_SECOND_EDITION_Code"

Rem Match 15: D:\Downloads\Books\9781787121706-MASTERING_C_MULTITHREADING_Code.zip
rmdir /s /q "K:\Test\9781787121706-MASTERING_C_MULTITHREADING_Code"

Rem Match 16: D:\Downloads\Books\9781787125445-MASTERING_BLOCKCHAIN_Code.zip
rmdir /s /q "K:\Test\9781787125445-MASTERING_BLOCKCHAIN_Code"

Rem Match 17: D:\Downloads\Books\9781787125643-GO_SYSTEMS_PROGRAMMING_Code.zip
rmdir /s /q "K:\Test\9781787125643-GO_SYSTEMS_PROGRAMMING_Code"

Rem Match 18: D:\Downloads\Books\9781787282049-PERL_6_DEEP_DIVE_Code.zip
rmdir /s /q "K:\Test\9781787282049-PERL_6_DEEP_DIVE_Code"

Rem Match 19: D:\Downloads\Books\9781788290142-MICROSOFT_POWER_BI_COOKBOOK_Code.zip
rmdir /s /q "K:\Test\9781788290142-MICROSOFT_POWER_BI_COOKBOOK_Code"

Rem Match 20: D:\Downloads\Books\9781788393850-ARCHITECTING_MODERN_JAVA_EE_APPLICATIONS_Code.zip
rmdir /s /q "K:\Test\9781788393850-ARCHITECTING_MODERN_JAVA_EE_APPLICATIONS_Code"

Rem Match 21: D:\Downloads\Books\9781788396646-DEVOPS_WITH_KUBERNETES_Code.zip
rmdir /s /q "K:\Test\9781788396646-DEVOPS_WITH_KUBERNETES_Code"

Rem Match 22: D:\Downloads\Books\Mastering Docker 2nd Edition_Code.zip
rmdir /s /q "K:\Test\Mastering Docker 2nd Edition_Code"

Rem Match 23: D:\Downloads\Books\Raspberry Pi Cookbook for Python Programmers - Code.zip
rmdir /s /q "K:\Test\Raspberry Pi Cookbook for Python Programmers - Code"


Source, note the comments at line 113 and 114 if you want to expand the filetypes or make it recurse through the extracted folder tree:

Code: ( powershell)
<# This form was created using POSHGUI.com  a free online gui designer for PowerShell
.NAME
    ArcDirMatcher.ps1
#>

#region begin GUI{ 

Add-Type -AssemblyName System.Windows.Forms
[System.Windows.Forms.Application]::EnableVisualStyles()

$Form                            = New-Object system.Windows.Forms.Form
$Form.ClientSize                 = '400,291'
$Form.text                       = "ArcDirMatcher"
$Form.TopMost                    = $false

$TextBox1                        = New-Object system.Windows.Forms.TextBox
$TextBox1.multiline              = $false
$TextBox1.width                  = 277
$TextBox1.height                 = 20
$TextBox1.location               = New-Object System.Drawing.Point(21,63)
$TextBox1.Font                   = 'Microsoft Sans Serif,17'

$Button1                         = New-Object system.Windows.Forms.Button
$Button1.text                    = "..."
$Button1.width                   = 60
$Button1.height                  = 30
$Button1.location                = New-Object System.Drawing.Point(316,63)
$Button1.Font                    = 'Microsoft Sans Serif,10'

$Label1                          = New-Object system.Windows.Forms.Label
$Label1.text                     = "Select folder with archives (recursive):"
$Label1.AutoSize                 = $true
$Label1.width                    = 25
$Label1.height                   = 10
$Label1.location                 = New-Object System.Drawing.Point(21,34)
$Label1.Font                     = 'Microsoft Sans Serif,12'

$Label2                          = New-Object system.Windows.Forms.Label
$Label2.text                     = "Select path of extracted folders (non-recursive):"
$Label2.AutoSize                 = $true
$Label2.width                    = 25
$Label2.height                   = 10
$Label2.location                 = New-Object System.Drawing.Point(21,130)
$Label2.Font                     = 'Microsoft Sans Serif,12'

$TextBox2                        = New-Object system.Windows.Forms.TextBox
$TextBox2.multiline              = $false
$TextBox2.width                  = 273
$TextBox2.height                 = 20
$TextBox2.location               = New-Object System.Drawing.Point(21,161)
$TextBox2.Font                   = 'Microsoft Sans Serif,17'

$Button2                         = New-Object system.Windows.Forms.Button
$Button2.text                    = "..."
$Button2.width                   = 60
$Button2.height                  = 30
$Button2.location                = New-Object System.Drawing.Point(316,161)
$Button2.Font                    = 'Microsoft Sans Serif,10'

$Button3                         = New-Object system.Windows.Forms.Button
$Button3.text                    = "Start"
$Button3.width                   = 90
$Button3.height                  = 30
$Button3.location                = New-Object System.Drawing.Point(155,230)
$Button3.Font                    = 'Microsoft Sans Serif,12'

$Form.controls.AddRange(@($TextBox1,$Button1,$Label1,$Label2,$TextBox2,$Button2,$Button3))

$Button1.Add_Click({
  $objForm = New-Object System.Windows.Forms.FolderBrowserDialog
  $objForm.Description = "Select folder containing archives"
  $objForm.SelectedPath = [System.Environment+SpecialFolder]'MyComputer'
  $objForm.ShowNewFolderButton = $false
  $result = $objForm.ShowDialog()
  if ($result -eq "OK") {
    $TextBox1.Text = $objForm.SelectedPath
  } else {
    $TextBox1.Text = ""
  }
})

$Button2.Add_Click({
  $objForm = New-Object System.Windows.Forms.FolderBrowserDialog
  $objForm.Description = "Select folder containing extracted archives"
  $objForm.SelectedPath = [System.Environment+SpecialFolder]'MyComputer'
  $objForm.ShowNewFolderButton = $false
  $result = $objForm.ShowDialog()
  if ($result -eq "OK") {
    $TextBox2.Text = $objForm.SelectedPath
  } else {
    $TextBox2.Text = ""
  }
})

$Button3.Add_Click({
  if (($TextBox2.Text -ne "") -and ($TextBox1.Text -ne "")) {
    Collect-Archives $TextBox2.Text $TextBox1.Text
  }
})

#endregion events }

#endregion GUI }

#Write your logic code here

Function Collect-Archives {
  param (
    [string]$path,
    [string]$drive
  )
  $Button3.Text = 'Working'
  $archives = Get-ChildItem -Path "$($drive)\*" -Recurse -Include *.arc,*.arj,*.zip,*.rar,*.7z # add more extensions if necessary
  $folders = Get-ChildItem -Path $path -Directory # add -Recurse if you want to recurse through the folders also
  $total = 0
  Out-File -FilePath ($drive + '\ArcDirMatcher.txt') -InputObject "Rem -- Replace 'Matches:' with 'rmdir /s /q' in a text editor,`r`nRem -- then rename the extension from '.txt' to '.cmd'`r`nRem -- and run it to remove folders.`r`n" -Encoding utf8
  for ($i = 0; $i -lt $archives.Count; $i++) {
    $folderName = ([io.path]::GetFileNameWithoutExtension($archives[$i]))
    for ($j = 0; $j -lt $folders.Count; $j++) {
      if ((Split-Path $folders[$j] -Leaf) -eq $folderName) {
        $total += 1
        $text = "Rem Match $($total): $($archives[$i])`r`nMatches: `"$($folders[$j].FullName)`"`r`n"
        Out-File -FilePath ($drive + '\ArcDirMatcher.txt') -InputObject $text -Append -Encoding utf8
      }
    }
  }
  $Button3.Text = 'Start'
  if ($total -ne 0) {
    Invoke-Item ($drive + '\ArcDirMatcher.txt')
  }
}

[void]$Form.ShowDialog()

Run it from the shortcut, edit the shortcut Target if it's not in the same folder as the script.

Code: (text)
%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -sta -noprofile -executionpolicy bypass -File "ArcDirMatcher.ps1"
"I will not follow where the path may lead, but I will go where there is no path, and I will leave a trail." - Muriel Strode, 1903
« Last Edit: January 24, 2019, 08:26 AM by 4wd »

CodeTRUCKER

  • Bush Flying... where I'd rather be.
  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,086
    • Participated in NANY Challenge Once
    • Military Service Badge - US Navy
4wd,

Thank you for such a comprehensive response. I don't pretend to understand it all at first blush, but I will study, try it and report back if I have any specific questions or (hopefully) to report success. I sometimes have seasons where simple coding is almost incomprehensible and my gimpy noodle has been acting up lately. LOL

Thanks again,
Calvin
DISCLAIMER - I have made and make many threads for questions and even project posts across the Internet. Unfortunately, many are in limbo because I cannot remember where they are at. If anyone knows of an open thread or an unanswered inquiry, please PM me. Thank you.
   
Notice: Unless stated otherwise, I receive no compensation for anything I post here.

chashnniel

  • Member
  • Joined in 2018
  • **
  • Posts: 127
2 4wd
i just test it and works like a charm!!! good job :Thmbsup:

Original address: https://www.donationcoder.com/forum/index.php?topic=47098.0