Skip to content

Instantly share code, notes, and snippets.

@advanceboy
Last active February 28, 2016 19:04
Show Gist options
  • Save advanceboy/058dc0b9cac83d0c2523 to your computer and use it in GitHub Desktop.
Save advanceboy/058dc0b9cac83d0c2523 to your computer and use it in GitHub Desktop.
Android の apk バックアップアプリ appmonster3 で SDカード にリビジョンごとにバックアップされた *.apk ファイルたちから、 最古ファイルと log10 毎の最新ファイル 以外をすべて削除・整理する。
$apkfiles = gci D:\Android\data\com.think_android.appmanagerpro\files\appmonster3\backup\*\rev\*.apk
$deletedlist = New-Object System.Collections.Generic.List[string];
$apkgrp | %{
$targets = $_.Group
$filessorted = $targets | ?{ $_.Length -NE 0 } | sort { [long][System.IO.Path]::GetFileNameWithoutExtension($_.Name) };
$saved = @();
$saved += $filessorted | select -First 1;
$saved += $filessorted | group { [System.Math]::Floor([System.Math]::Log10( [long][System.IO.Path]::GetFileNameWithoutExtension($_.Name) )) } | %{ $_.Group | select -Last 1; };
$targets -notcontains $saved;
$deleted = $targets | ?{ $saved -notcontains $_ };
$deletedlist.AddRange([string[]]($deleted | %{ $_.FullName }));
$deleted | del;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment