-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathremove_dupe_files.ps1
61 lines (52 loc) · 1.64 KB
/
remove_dupe_files.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
50
51
52
53
54
55
56
57
58
59
60
61
# $Id: remove_dupe_files.ps1,v 1.4 2009/10/31 15:17:34 powem Exp $
#
# Remove duplicate SDC log files from the original
# directory
# location of the SDC share.
[string]$SdcStorage = "\\ctpowem01\share\logs\test1";
# location of the WebTrends log archive share.
[string]$WtStorage = "\\ctpowem01\share\logs\test2";
# Can't set a String in PS to $null, it will be coerced to "".
[string]$errPath="";
$global:dupeTotal = 0;
function removeDuplicateFiles(){
Write-Host "Gathering source files ... ";
$srcList = @(Get-ChildItem -Name $SdcStorage -Include "*.log");
Write-Host $srcList.length " source files.";
Write-Host "Gathering destination files ... ";
$destListNames = @(Get-ChildItem -Name $WtStorage -Include "*.log");
Write-Host $destListNames.length " destination files.";
$dupeCount = 0;
if ($srcList -eq $null){
$errPath = "(Origin) " + $SdcStorage;
Throw New-Object System.IO.FileNotFoundException;
}
if ($destListNames -eq $null){
$errPath = "(Dest) " + $WtStorage;
Throw New-Object System.IO.FileNotFoundException;
}
foreach ($file in $srcList){
for($i=0; $i -lt $destListNames.length; $i++){
if ($file.Equals($destListNames[$i])){
Remove-Item "$SdcStorage\$file";
$dupeCount++;
$global:dupeTotal = $dupeCount;
break;
}
if ($dupeCount % 100 -eq 0){
Write-Host $dupeCount " files deleted.";
}
}
# Write-Host $file.Name;
}
trap [System.IO.FileNotFoundException] {
Write-Host $_.Exception.Message;
Write-Host "Path: $errPath";
exit 1;
}
} # end function
& {
removeDuplicateFiles;
Write-Host "End duplicate file removal process.";
Write-Host "$global:dupeTotal duplicate files removed.";
}