Created
April 23, 2025 01:21
-
-
Save cbaragao/75c0eb46933d36aabcff7ea37ff9a01c to your computer and use it in GitHub Desktop.
This file contains hidden or 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 Get-RecentFiles { | |
| param ( | |
| [string]$Path = ".", | |
| [int]$Days = 1, | |
| [switch]$Recurse, | |
| [string]$Extension | |
| ) | |
| if (-Not (Test-Path $Path)) { | |
| Write-Error "Path not found: $Path" | |
| return | |
| } | |
| $cutoff = (Get-Date).AddDays(-$Days) | |
| $files = Get-ChildItem -Path $Path -File -Recurse:$Recurse | | |
| Where-Object { $_.LastWriteTime -gt $cutoff -and $_.Extension -eq $Extension} | |
| return $files | Select-Object Name, LastWriteTime, Length, FullName | |
| } | |
| $file = Get-RecentFiles -Path "C:\Path\To\Files" -Days 100 -Recurse -Extension ".csv" | |
| $file | Format-Table |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment