-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathrename-dirItems.ps1
More file actions
42 lines (40 loc) · 818 Bytes
/
rename-dirItems.ps1
File metadata and controls
42 lines (40 loc) · 818 Bytes
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
<#
.Synopsis
Easy rename all files in a folder
.DESCRIPTION
Sorting all files be creation time in the folder, sequentially number them starting at 1.
Prefixed by the given filename
Keeping their existing extension
.EXAMPLE
Rename-DirItems PartsOfThisMovie
PartsOfThisMovie-1.m4v
PartsOfThisMovie-2.m4v
PartsOfThisMovie-3...
#>
function Rename-DirItems
{
[CmdletBinding()]
Param
(
# File Name before number to increment
[Parameter(Mandatory=$true,
Position=0)]
$prefix
)
Begin
{
$i = 1
}
Process
{
Get-ChildItem |
Sort-Object -Property Creationtime |
foreach{
Rename-Item -path $_ -NewName "$prefix-$i.$($_.Extension)"
$i++
}
}
End
{
}
}