-
Notifications
You must be signed in to change notification settings - Fork 0
/
Remove-ExtraFiles.ps1
49 lines (45 loc) · 1.31 KB
/
Remove-ExtraFiles.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<#
.Synopsis
Removes extra files that are sometimes included in media downloads.
.DESCRIPTION
Removes extra files that are sometimes included in media downloads.
Some sites include .exe, .nfo, or .txt files in addition to media files.
.EXAMPLE
.\Remove-ExtraFiles.ps1 'path/to/media'
#>
[CmdletBinding()]
Param
(
# Path to the directory to rename subs in
[Parameter(Mandatory = $true, Position = 0)]
$Path
)
# Remove any .exe, .nfo, or .txt files from the folders.
# This SHOULD work but is deleting all the files in the directory.
$fileTypes = @('.exe', '.nfo', '.txt')
$filesToRemove = Get-ChildItem -LiteralPath $Path | Where-Object { $_.Extension -in $fileTypes }
if ($filesToRemove.count -gt 0)
{
$filestoremove | Remove-Item
$logText = "Extra files removed from: $Path"
Write-Output $logText
}
else
{
$logText = "No extra files found in: $Path."
Write-Warning $logtext
}
# Remove any "samples" subdir
$sampleDirectoryName = 'sample*'
$sampleDirectories = Get-ChildItem -LiteralPath $Path -Directory -Filter $sampleDirectoryName
if ($sampleDirectories.count -gt 0)
{
$sampleDirectories | Remove-Item -Force
$logText = "Sample directories removed from: $Path"
Write-Output $logText
}
else
{
$logText = "No sample directories found in: $Path"
Write-Output $logText
}