topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • March 19, 2019, 02:14 PM
  • Proudly celebrating 13 years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: FindZipFilenameAndFolder.zip & FindZipFilenameAndFolder Folder Finder  (Read 544 times)

CodeTRUCKER

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,071
    • View Profile
    • Donate to Member
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

 

4wd

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 5,160
    • View Profile
    • Donate to Member
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 [Select]
  1. <# This form was created using POSHGUI.com  a free online gui designer for PowerShell
  2. .NAME
  3.     ArcDirMatcher.ps1
  4. #>
  5.  
  6. #region begin GUI{
  7.  
  8. Add-Type -AssemblyName System.Windows.Forms
  9. [System.Windows.Forms.Application]::EnableVisualStyles()
  10.  
  11. $Form                            = New-Object system.Windows.Forms.Form
  12. $Form.ClientSize                 = '400,291'
  13. $Form.text                       = "ArcDirMatcher"
  14. $Form.TopMost                    = $false
  15.  
  16. $TextBox1                        = New-Object system.Windows.Forms.TextBox
  17. $TextBox1.multiline              = $false
  18. $TextBox1.width                  = 277
  19. $TextBox1.height                 = 20
  20. $TextBox1.location               = New-Object System.Drawing.Point(21,63)
  21. $TextBox1.Font                   = 'Microsoft Sans Serif,17'
  22.  
  23. $Button1                         = New-Object system.Windows.Forms.Button
  24. $Button1.text                    = "..."
  25. $Button1.width                   = 60
  26. $Button1.height                  = 30
  27. $Button1.location                = New-Object System.Drawing.Point(316,63)
  28. $Button1.Font                    = 'Microsoft Sans Serif,10'
  29.  
  30. $Label1                          = New-Object system.Windows.Forms.Label
  31. $Label1.text                     = "Select folder with archives (recursive):"
  32. $Label1.AutoSize                 = $true
  33. $Label1.width                    = 25
  34. $Label1.height                   = 10
  35. $Label1.location                 = New-Object System.Drawing.Point(21,34)
  36. $Label1.Font                     = 'Microsoft Sans Serif,12'
  37.  
  38. $Label2                          = New-Object system.Windows.Forms.Label
  39. $Label2.text                     = "Select path of extracted folders (non-recursive):"
  40. $Label2.AutoSize                 = $true
  41. $Label2.width                    = 25
  42. $Label2.height                   = 10
  43. $Label2.location                 = New-Object System.Drawing.Point(21,130)
  44. $Label2.Font                     = 'Microsoft Sans Serif,12'
  45.  
  46. $TextBox2                        = New-Object system.Windows.Forms.TextBox
  47. $TextBox2.multiline              = $false
  48. $TextBox2.width                  = 273
  49. $TextBox2.height                 = 20
  50. $TextBox2.location               = New-Object System.Drawing.Point(21,161)
  51. $TextBox2.Font                   = 'Microsoft Sans Serif,17'
  52.  
  53. $Button2                         = New-Object system.Windows.Forms.Button
  54. $Button2.text                    = "..."
  55. $Button2.width                   = 60
  56. $Button2.height                  = 30
  57. $Button2.location                = New-Object System.Drawing.Point(316,161)
  58. $Button2.Font                    = 'Microsoft Sans Serif,10'
  59.  
  60. $Button3                         = New-Object system.Windows.Forms.Button
  61. $Button3.text                    = "Start"
  62. $Button3.width                   = 90
  63. $Button3.height                  = 30
  64. $Button3.location                = New-Object System.Drawing.Point(155,230)
  65. $Button3.Font                    = 'Microsoft Sans Serif,12'
  66.  
  67. $Form.controls.AddRange(@($TextBox1,$Button1,$Label1,$Label2,$TextBox2,$Button2,$Button3))
  68.  
  69. $Button1.Add_Click({
  70.   $objForm = New-Object System.Windows.Forms.FolderBrowserDialog
  71.   $objForm.Description = "Select folder containing archives"
  72.   $objForm.SelectedPath = [System.Environment+SpecialFolder]'MyComputer'
  73.   $objForm.ShowNewFolderButton = $false
  74.   $result = $objForm.ShowDialog()
  75.   if ($result -eq "OK") {
  76.     $TextBox1.Text = $objForm.SelectedPath
  77.   } else {
  78.     $TextBox1.Text = ""
  79.   }
  80. })
  81.  
  82. $Button2.Add_Click({
  83.   $objForm = New-Object System.Windows.Forms.FolderBrowserDialog
  84.   $objForm.Description = "Select folder containing extracted archives"
  85.   $objForm.SelectedPath = [System.Environment+SpecialFolder]'MyComputer'
  86.   $objForm.ShowNewFolderButton = $false
  87.   $result = $objForm.ShowDialog()
  88.   if ($result -eq "OK") {
  89.     $TextBox2.Text = $objForm.SelectedPath
  90.   } else {
  91.     $TextBox2.Text = ""
  92.   }
  93. })
  94.  
  95. $Button3.Add_Click({
  96.   if (($TextBox2.Text -ne "") -and ($TextBox1.Text -ne "")) {
  97.     Collect-Archives $TextBox2.Text $TextBox1.Text
  98.   }
  99. })
  100.  
  101. #endregion events }
  102.  
  103. #endregion GUI }
  104.  
  105. #Write your logic code here
  106.  
  107. Function Collect-Archives {
  108.   param (
  109.     [string]$path,
  110.     [string]$drive
  111.   )
  112.   $Button3.Text = 'Working'
  113.   $archives = Get-ChildItem -Path "$($drive)\*" -Recurse -Include *.arc,*.arj,*.zip,*.rar,*.7z # add more extensions if necessary
  114.   $folders = Get-ChildItem -Path $path -Directory # add -Recurse if you want to recurse through the folders also
  115.   $total = 0
  116.   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
  117.   for ($i = 0; $i -lt $archives.Count; $i++) {
  118.     $folderName = ([io.path]::GetFileNameWithoutExtension($archives[$i]))
  119.     for ($j = 0; $j -lt $folders.Count; $j++) {
  120.       if ((Split-Path $folders[$j] -Leaf) -eq $folderName) {
  121.         $total += 1
  122.         $text = "Rem Match $($total): $($archives[$i])`r`nMatches: `"$($folders[$j].FullName)`"`r`n"
  123.         Out-File -FilePath ($drive + '\ArcDirMatcher.txt') -InputObject $text -Append -Encoding utf8
  124.       }
  125.     }
  126.   }
  127.   $Button3.Text = 'Start'
  128.   if ($total -ne 0) {
  129.     Invoke-Item ($drive + '\ArcDirMatcher.txt')
  130.   }
  131. }
  132.  
  133. [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 [Select]
  1. %SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -sta -noprofile -executionpolicy bypass -File "ArcDirMatcher.ps1"
« Last Edit: January 24, 2019, 02:26 AM by 4wd »

CodeTRUCKER

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,071
    • View Profile
    • Donate to Member
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

chashnniel

  • Member
  • Joined in 2018
  • **
  • default avatar
  • Posts: 59
    • View Profile
    • Donate to Member
2 4wd
i just test it and works like a charm!!! good job :Thmbsup: