-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.psm1
53 lines (42 loc) · 1.2 KB
/
functions.psm1
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
50
51
52
53
<#
.DESCRIPTION
Some useful functions.
#>
<#
.SYNOPSIS
Changes the extensions of all files in a directory.
.DESCRIPTION
Changes the extensions of all files in a directory.
.PARAMETER location
Directory location of the files
.PARAMETER ext
The target extension name.
.PARAMETER exclude
Files to exclude
.EXAMPLE
ChangeFileExtensions . jpg *.ps1, *.psm1
.NOTES
General notes
#>
function ChangeFileExtensions {
Param(
[Parameter(Mandatory = $True, Position = 1, HelpMessage = "Enter files' location")]
[string]
$location,
[Parameter(Mandatory = $True, Position = 2, HelpMessage = "Enter extension")]
[string]
$ext,
[Parameter(Mandatory = $False, Position = 3, HelpMessage = "Exclude these files")]
[string[]]
$exclude
)
if($ext.StartsWith(".")) {
$ext = $ext.Replace(".", "")
}
Get-ChildItem $location -Exclude $exclude |
Foreach-Object {
Write-Host "Changing the extension of $($_.FullName) to .$ext .." -ForegroundColor Blue
Rename-Item $_.FullName "$($_.BaseName).$ext"
}
Write-Host "Finished changing the extensions of all files." -ForegroundColor Blue
}