Skip to content

Instantly share code, notes, and snippets.

@naotea
Created June 29, 2024 08:12
Show Gist options
  • Save naotea/4dc2f65702fb86c714cb9ff598b6b5d5 to your computer and use it in GitHub Desktop.
Save naotea/4dc2f65702fb86c714cb9ff598b6b5d5 to your computer and use it in GitHub Desktop.
同内容TSファイルの重複を探す
# 同内容TSファイルの重複を探す
# "タイトル_放送回_サブタイトル_日付.ts" 形式のTSファイルの
# タイトルと放送回が同じファイルが同フォルダ存在したら表示
#
# Find-SimilarFiles.bat [Folder]
#
# 引数にフォルダを指定した場合、その配下を探す
# デフォルト対象フォルダ
$rootFolder = "D:\tv"
# ファイル名比較
function Check-DupFilename {
param ([string]$source, [string]$target)
$re = "^([^_]+_[.\d]+)_.*.ts$"
if($source -match $re){$s = $Matches.1}
if($target -match $re){$t = $Matches.1}
if($s -ne $null -and $t -ne $null -and $s -ceq $t) {$true} else {$false}
}
# 指定フォルダ下を再帰調査し結果を出力
function Find-SimilarFiles {
param ([string]$rootFolder)
$folders = (Get-ChildItem -Path $rootFolder -Directory | Sort-Object -Property Name)
$files = (Get-ChildItem -Path $rootFolder -File | Sort-Object -Property Name)
foreach ($file in $files)
{
if (Check-DupFilename -source $prev.Name -target $file.Name)
{
Write-Output $prev.Fullname
}
$prev = $file
}
foreach ($folder in $folders)
{
Find-SimilarFiles -rootFolder $folder.FullName
}
}
#初期値設定、実行
if ($Args.Count -gt 0) {$rootFolder = $Args[0]}
Write-Output $rootFolder
Find-SimilarFiles -rootFolder $rootFolder
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment