Skip to content

Commit 458c038

Browse files
committed
fix: Still trying to delete the repo files properly
1 parent c0a2afa commit 458c038

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

_InitializeRepository.ps1

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,22 @@ Begin
2525

2626
function Remove-AllRepositoryFilesExceptTemplateModuleFiles
2727
{
28-
Get-ChildItem -Path $RepositoryRoot -Recurse |
28+
# Delete all files except the ones we want to keep.
29+
Get-ChildItem -Path $RepositoryRoot -Recurse -File |
2930
Where-Object {
3031
$_.FullName -notlike "$RepositoryRoot\.git\*" -and # Don't delete the .git directory.
3132
$_.FullName -notlike "$RepositoryRoot\_InitializeRepository.ps1" -and # Don't delete this script.
3233
$_.FullName -notlike "$RepositoryRoot\src\Template.PowerShell.ScriptModule\*" # Don't delete the template module files.
3334
} |
3435
Remove-Item -Force
36+
37+
# Delete all empty directories that were left behind.
38+
Get-ChildItem -Path $RepositoryRoot -Recurse -Directory |
39+
Sort-Object -Property FullName -Descending | # Delete child directories before parent directories.
40+
Where-Object {
41+
$_.GetFileSystemInfos().Count -eq 0
42+
} |
43+
Remove-Item -Force
3544
}
3645

3746
function Copy-TemplateFilesToRepositoryRoot

0 commit comments

Comments
 (0)