-
Notifications
You must be signed in to change notification settings - Fork 1
/
MoveToBin.ps1
30 lines (25 loc) · 1.05 KB
/
MoveToBin.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
param (
[string] $p1
)
$sourceDir = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath("$p1");
$targetDir = (Join-Path $sourceDir "bin\");
# Create the bin folder
New-Item "$targetDir" -ItemType Directory -Force;
# Move all files to the bin folder, relative to their current path
Get-ChildItem $sourceDir -Include "*.dll", "*.pdb", "*.xml" -Recurse -File | `
foreach {
$sourceFile = $_.FullName;
$relativeFile = $sourceFile.SubString($sourceDir.Length);
if (!($relativeFile.StartsWith("bin\"))) {
$targetFile = $targetDir + $relativeFile;
$targetFileDir = (Split-Path $targetFile -Parent);
New-item $targetFileDir -ItemType Directory -Force;
Move-Item $sourceFile -Destination $targetFile;
}
};
# Recursively delete all empty directories
# https://stackoverflow.com/a/28631669/7517185
do {
$dirs = gci $sourceDir -Directory -Recurse | Where { (gci $_.fullName -Force).Count -eq 0 } | Select -ExpandProperty FullName
$dirs | Foreach-Object { Remove-Item $_ -Force }
} while ($dirs.count -gt 0)