Created
September 7, 2023 21:25
-
-
Save azam/62d16988699af4a22db5dae627a09ea9 to your computer and use it in GitHub Desktop.
Powershell function to print recent files recursively, defaults to last 1 day
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Print-RecentFiles { | |
Param ( | |
[Parameter()][string]$Path, | |
[Parameter()][switch]$NoRecurse, | |
[Parameter()][int]$Days = 1, | |
[Parameter()][int]$Hours = 0, | |
[Parameter()][int]$Minutes = 0, | |
[Parameter()][int]$Seconds = 0 | |
) | |
if([string]::IsNullOrWhiteSpace($Path)){ | |
$Path = $PWD | |
} | |
$Recurse = ! $NoRecurse.IsPresent | |
$Info = (Get-Item $Path) | |
$From = Get-Date | |
$From = $From.AddDays(-$Days) | |
$From = $From.AddHours(-$Hours) | |
$From = $From.AddMinutes(-$Minutes) | |
$From = $From.AddSeconds(-$Seconds) | |
if ($Info -is [System.IO.DirectoryInfo]) { | |
$Items = (Get-ChildItem -File -Path $Path -Recurse:$Recurse -Include * | Where-Object {$_.LastWriteTime -gt $From}) | |
foreach ($Item in $Items) { | |
Write-Host $Item.LastWriteTime $Item | |
} | |
} elseif ($Info -is [System.IO.FileInfo]) { | |
if ($Info.LastWriteTime -gt $From) { | |
Write-Host $Info.LastWriteTime $Info | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment