PowerShell: List files modified after xx and watch files

kenakamu

Kenichiro Nakamura

Posted on September 25, 2022

PowerShell: List files modified after xx and watch files

This is just a memo for myself.

List files modified after x seconds.

  • Recurse: include subdirectories
  • Force: include hidden files
  • File: file only
Get-ChildItem -Recurse -Force -File | `
where LastWriteTime -gt (Get-Date).AddSeconds(-10) | `
select Name, LastWriteTime
Enter fullscreen mode Exit fullscreen mode

Show tree structure of specified folder.

tree /F <folder>
Enter fullscreen mode Exit fullscreen mode

Watch object creation and update of specified folder.


$watcher = New-Object System.IO.FileSystemWatcher
$watcher.Path = "my files path"
$watcher.EnableRaisingEvents = $true
$watcher.IncludeSubdirectories = $true
$action = {
    $fullPath = $event.SourceEventArgs.FullPath
    $name = $event.SourceEventArgs.Name
    $changeType = $event.SourceEventArgs.ChangeType
    Write-Host "$changeType $name $path"
}
Register-ObjectEvent $watcher 'Changed' -Action $action
#Get-EventSubscriber | Unregister-Event
Enter fullscreen mode Exit fullscreen mode
💖 💪 🙅 🚩
kenakamu
Kenichiro Nakamura

Posted on September 25, 2022

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related