Added list-empty-files.ps1

This commit is contained in:
Markus Fleschutz
2021-02-10 18:37:55 +01:00
parent cf7b28a93f
commit 61b0c3e65d
4 changed files with 26 additions and 1 deletions

View File

@ -13,8 +13,9 @@ try {
$DirTree = read-host "Enter the path to the directory tree"
}
write-progress "Checking symlinks in $DirTree..."
[int]$SymlinksTotal = [int]$SymlinksBroken = 0
gci $DirTree -Recurse | Where { $_.Attributes -match "ReparsePoint" } | ForEach-Object {
Get-ChildItem $DirTree -recurse | Where { $_.Attributes -match "ReparsePoint" } | ForEach-Object {
$Symlink = $_.FullName
$Target = ($_ | Select-Object -ExpandProperty Target -ErrorAction Ignore)
if ($Target) {

22
Scripts/list-empty-files.ps1 Executable file
View File

@ -0,0 +1,22 @@
#!/bin/powershell
<#
.SYNTAX ./list-empty-files.ps1 [<dir-tree>]
.DESCRIPTION lists empty files within the given directory tree
.LINK https://github.com/fleschutz/PowerShell
.NOTES Author: Markus Fleschutz / License: CC0
#>
param($DirTree = "")
try {
if ($DirTree -eq "" ) {
$DirTree = read-host "Enter the path to the directory tree"
}
write-progress "Listing empty files in $DirTree ..."
Get-ChildItem $DirTree -recurse | Where {$_.PSIsContainer -eq $false} | Where {$_.Length -eq 0} | select FullName
echo "Done."
exit 0
} catch {
write-error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}