Created
September 5, 2018 10:35
-
-
Save nyanshiba/7ab0d186740034f7788830f0009780e1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#--------------------tsの自動削除の設定-------------------- | |
#録画フォルダの上限 超過した場合、toggle=0:容量警告(Twitter、Discord) 1:削除 | |
$ts_folder_max=7TB | |
#====================ts・mp4の自動削除==================== | |
#フォルダの合計サイズを設定値以下に丸め込む関数 | |
function FolderRound { | |
#初期値 | |
$delcnt=-1 | |
#必ず1回は実行、フォルダ内の新しいファイルをSkipする数$iを増やしていって$maintsizeを$ts_folder_max以下に丸め込むループ | |
do { | |
$delcnt++ | |
$maintsize=(Get-ChildItem "$env:FolderPath\*.ts" | Sort-Object LastWriteTime -Descending | Select-Object -Skip $delcnt | Measure-Object -Sum Length).Sum | |
} while ($maintsize -gt $ts_folder_max) | |
#先程Skipしたファイルを実際に削除 | |
Get-ChildItem "$env:FolderPath\*.ts" | Sort-Object LastWriteTime | Select-Object -First $delcnt | ForEach-Object { | |
#tsかmp4を削除 | |
Remove-Item -LiteralPath "$env:FolderPath\$($_.BaseName).ts" -ErrorAction SilentlyContinue | |
$dellog="削除:$($_.BaseName).ts" | |
#tsを削除中の場合、同名のts.program.txt、ts.errも削除 | |
if ("ts" -eq "ts") { | |
Remove-Item -LiteralPath "$env:FolderPath\$($_.BaseName).ts.program.txt" -ErrorAction SilentlyContinue | |
Remove-Item -LiteralPath "$env:FolderPath\$($_.BaseName).ts.err" -ErrorAction SilentlyContinue | |
$dellog+="、.program.txt、.err" | |
} | |
Write-Output $dellog | |
} | |
Write-Output "${delext}フォルダ:$([math]::round(${maintsize}/1GB,2))GB" | |
} | |
#ts | |
FolderRound |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment