topbanner_forum
  *

avatar image

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

Login with username, password and session length
  • Sunday December 15, 2024, 11:16 pm
  • Proudly celebrating 15+ 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: DONE: In sub-folders, delete all files except the largest  (Read 10643 times)

nkormanik

  • Participant
  • Joined in 2010
  • *
  • Posts: 554
    • View Profile
    • Donate to Member
DONE: In sub-folders, delete all files except the largest
« on: August 14, 2018, 12:23 AM »
Given a folder, XYZ.  Look in sub-folders.  If more than one file exists within any one sub-folder, delete all except the largest file present.

Issue has arisen from capturing streaming audio 'radio stations' around the Internet.

One folder has 22 different copies of Queen's Radio Ga Ga.  Another, 20 copies of Madona's Like A Prayer. 18 MJ's Billie Jean.  And on and on.

Need a way to pare out the littler ones, I suppose.  Not the very best solution, because there is often announcer voice at the beginning of the longer items -- that's actually why they are longer.  But, keeping the longest/biggest seems the best bet I can think of.

Question is, how does one do this?

Hundreds of sub-folders, by the way.  So need an auto way.

Thanks!

Nicholas Kormanik

KodeZwerg

  • Honorary Member
  • Joined in 2018
  • **
  • Posts: 718
    • View Profile
    • Donate to Member
Re: DONE: In sub-folders, delete all files except the largest
« Reply #1 on: August 14, 2018, 02:47 AM »
How about a safer reverse way, automatic copy biggest file inside sub-folder to new location, if you afterwards wish, delete that source folder.

nkormanik

  • Participant
  • Joined in 2010
  • *
  • Posts: 554
    • View Profile
    • Donate to Member
Re: DONE: In sub-folders, delete all files except the largest
« Reply #2 on: August 14, 2018, 04:06 AM »
Wow!  Outstanding thinking, KodeZwerg.

Now, how to go about doing THAT?

Perhaps copy to XYZ_Biggest....

highend01

  • Supporting Member
  • Joined in 2011
  • **
  • Posts: 188
    • View Profile
    • Donate to Member
Re: DONE: In sub-folders, delete all files except the largest
« Reply #3 on: August 14, 2018, 04:46 AM »
Try the attached file (with some testdata folders first!)

VT: https://www.virustot...analysis/1534240206/

Works fine here...
« Last Edit: August 14, 2018, 04:57 AM by highend01 »

anandcoral

  • Honorary Member
  • Joined in 2009
  • **
  • Posts: 783
    • View Profile
    • Free Portable Apps
    • Donate to Member
Re: DONE: In sub-folders, delete all files except the largest
« Reply #4 on: August 14, 2018, 04:53 AM »
Hi Nicholas,

highend01 already gave to solution. Still I have attached two batch files I use to "delete all but latest 6 zip files in all subdirectories", i.e. instead of size it checks date. Since they are batch files, you may modify them as per your requirement.

Regards,

Anand

KodeZwerg

  • Honorary Member
  • Joined in 2018
  • **
  • Posts: 718
    • View Profile
    • Donate to Member
Re: DONE: In sub-folders, delete all files except the largest
« Reply #5 on: August 14, 2018, 04:59 AM »
I have not figured out given solutions, if still needed, i could create a CopyBiggestToNewLocation type of app.

4wd

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 5,644
    • View Profile
    • Donate to Member
Re: DONE: In sub-folders, delete all files except the largest
« Reply #6 on: August 14, 2018, 06:43 AM »
Quick and dirty:

Code: PowerShell [Select]
  1. Get-ChildItem <SRCE> -Recurse -Directory | % { Get-ChildItem $_.FullName -File | Sort-Object Length -Descending | Select-Object -First 1 | Copy-Item -Destination <DEST> }

Change <SRCE> to the source directory, (eg. Z:\test -- the parent of all the sub-directories), change <DEST> to the destination directory, (eg. K:\output), and it should copy the largest file in every sub-directory of the source to the destination, (directory tree is NOT preserved).

If there's an existing file of the same name it'll just skip copying that file, (ie. nothing gets overwritten).

eg.
Code: PowerShell [Select]
  1. Get-ChildItem Z:\test -Recurse -Directory | % { Get-ChildItem $_.FullName -File | Sort-Object Length -Descending | Select-Object -First 1 | Copy-Item -Destination K:\output }

rjbull

  • Charter Member
  • Joined in 2005
  • ***
  • default avatar
  • Posts: 3,205
    • View Profile
    • Donate to Member
Re: DONE: In sub-folders, delete all files except the largest
« Reply #7 on: August 14, 2018, 04:58 PM »
If I understand you correctly...  here's a GUI method.

Download Robert Vasicek's Cathy media cataloguing tool.  It's tiny, fast, portable and postcard-ware.  Set up the directories you want to check, make catalogues of them - no need for separate ones if they're in the same part of the tree, just include subdirectories, but mine were well separated.  Cathy can also make catalogues of CDs, DVDs, etc., i.e. offline holdings, so you can check them at the same time:

Cathy_catalog.jpgDONE: In sub-folders, delete all files except the largest

You can make one or more catalogues, highlight all the ones you want to search.  Tell it what sort of files you want to search for, in my case, *.JPG.  Then tell it you want to search not Duplicates, but Same names:

Cath_same_names.jpgDONE: In sub-folders, delete all files except the largest

Then hit the Search button.  You can sort the resulting list by clicking the Length column:

Cathy_duplicates_sorted_by_size.jpgDONE: In sub-folders, delete all files except the largest

You get a Right-Click menu, though it may not do enough for you:

Cath_Right_Click_menu.pngDONE: In sub-folders, delete all files except the largest

There are plenty of other duplicate finder out there, e.g. the excellent Double Killer (free and payware versions): Nir Sofer's SearchMyFiles has a Duplicates mode: so does XYplorer...
« Last Edit: August 15, 2018, 03:00 PM by rjbull »

nkormanik

  • Participant
  • Joined in 2010
  • *
  • Posts: 554
    • View Profile
    • Donate to Member
Re: DONE: In sub-folders, delete all files except the largest
« Reply #8 on: August 14, 2018, 05:17 PM »
highend01 seems to have accomplished the task perfectly.  What magic!

His little gem is a significant addition to the utilities in our tool bags.

Thanks very much, highend01!  And to all the rest of you.

Skwire, another success....

highend01

  • Supporting Member
  • Joined in 2011
  • **
  • Posts: 188
    • View Profile
    • Donate to Member
Re: DONE: In sub-folders, delete all files except the largest
« Reply #9 on: August 15, 2018, 02:12 PM »
I had the time to improve my version (a tiny bit)...

It now creates a log file (in %TEMP%) with the files that have been deleted and
automatically opens it with the associated application afterwards

It should be about 10-20 times faster than the old version (on fast hardware like SSDs)
because of better designed structures and ways to find the largest file...
« Last Edit: August 15, 2018, 02:21 PM by highend01 »

nkormanik

  • Participant
  • Joined in 2010
  • *
  • Posts: 554
    • View Profile
    • Donate to Member
Re: DONE: In sub-folders, delete all files except the largest
« Reply #10 on: August 16, 2018, 06:45 PM »
Thanks again, highend01.  Amazing work.

skwire

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 5,287
    • View Profile
    • Donate to Member
Re: DONE: In sub-folders, delete all files except the largest
« Reply #11 on: August 17, 2018, 05:34 PM »
Thanks to all contributors on this thread.   :Thmbsup:  I'll move it.