-
Notifications
You must be signed in to change notification settings - Fork 0
/
MuhamadBestagiRomadhon-bestagi.egi@live.com.ps1
43 lines (35 loc) · 1.38 KB
/
MuhamadBestagiRomadhon-bestagi.egi@live.com.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
#Script template
function listChildFolder($folderPath) {
#write your script here
#checking object folder path before starting sorting object
#this checking folder not spend time because prevent enumeration
#but have a limitation on doesn't exist folder path
#please ignore the message and focus on Error messages
if((Get-ChildItem $folderPath | Select-Object -First 1 | Measure-Object).Count -eq 0){"Folder Empty"}
try{
Get-ChildItem $folderPath -ErrorAction Stop | Select-Object LastWriteTime, Name | Sort-Object LastWriteTime -Descending
}
Catch {
Write-Host "Error :" $_.Exception.Message -ForegroundColor Red
}
return
}
#Example call function, remove the "#" sign below to a call, dont forget to configure a path
#listChildFolder -folderPath D:\Test
function compareTwoFiles($firstFilePath, $secondFilePath) {
#write your script here
$size1 = ((Get-Item $firstFilePath).Length)
$size2 = ((Get-Item $secondFilePath).Length)
if ($size1 -gt $size2) {
[io.path]::GetFileName($firstFilePath)
}
ElseIf ($size1 -lt $size2) {
[io.path]::GetFileName($secondFilePath)
}
Else {
"both file has same size"
}
return
}
#Example call function, remove the "#" sign below to a call, dont forget to configure a path
#compareTwoFiles -firstFilePath "D:\Test\File 1" -secondFilePath "D:\Test\File 2"