반응형
Windows 에서 파일을 관리 하는 경우 Powershell 을 사용하면 매우 편리합니다. 대부분의 파일 작업은 반복되는 작업인 경우가 많습니다. 이런 작업들을 Powershell 스크립트로 한번 작성 해 놓고 반복해서 사용한다면 매우 편리 할 것입니다.
요즘 많은 분들이 컴퓨터를 사용하여 드라마를 다운로드 받아서 볼 텐데 동일한 드라마에 대한 여러 해상도의 파일을 다운로드 받는 경우가 종종 있습니다. 이런 경우 저는 낮은 해상도의 파일은 지웁니다.
아래는 중복된 파일이 있는 경우의 예입니다. E06 회차의 드라마에 대해 1080p, 720p 의 드라마가 중복되는 것을 확인 할 수 있습니다. 이런 경우 저는 높은 해상도의 파일은 남겨 놓고 낮은 해상도의 파일은 지웁니다.
[tvN] 나의 아저씨.E06.180405.1080p-NEXT.mp4
[tvN] 나의 아저씨.E06.180405.720p-NEXT.mp4
이를 위한 Powershell 스크립트는 아래와 같습니다. 아래 파일에서 ‘드라마폴더경로’ 부분만 본인의 폴더 경로에 맞도록 수정후에 실행하면 될 겁니다.
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
cd 드라마폴더경로 | |
$d = gci .\*.mp4 | |
$t = $d | ForEach { | |
$s = $_.Name | |
$tt = $s -match '(E\d+).*((360|720|1080)p)' | |
$v = $matches[1] | |
$p = [int]$matches[3] | |
New-Object PSObject -Property @{ | |
EV = $v | |
Value = $p | |
Fullpath = $_.FullName | |
Name = $_.Name | |
} | |
} | |
$original = $t | Sort-Object -Property @{Expression="EV";Descending=$false}, @{Expression="Value";Descending=$false} | |
$unique = $original | Sort-Object -Property EV -Unique | |
$original.Count | |
$unique.Count | |
Compare-Object -referenceobject $original -differenceobject $unique -Property Fullpath | |
Compare-Object -referenceobject $original -differenceobject $unique -Property Fullpath | % {Remove-Item -LiteralPath $_.Fullpath -force} | |
반응형
'programming language > powershell' 카테고리의 다른 글
Windows Powershell 탐색기에서 미리보기 설정하기 (0) | 2019.03.25 |
---|---|
Powershell xml parsing (0) | 2019.01.30 |
Powershell 을 사용하여 레지스트리 값 변경하기 (0) | 2018.10.07 |
Powershell 을 사용하여 COM(Component Object Model) 에서 사용가능한 함수 및 속성 알아내는 방법 (0) | 2018.05.07 |
Powershell 에서 C# 으로 만들어진 DLL 사용하기 (0) | 2017.12.28 |
Powershell utf8 with/without BOM 파일 저장 (0) | 2017.07.27 |
Powershell v5.0 설치 (0) | 2017.02.19 |
Powershell 지난 주 이전의 파일 지우기 (0) | 2017.02.18 |
댓글