DEV Community

Kenichiro Nakamura
Kenichiro Nakamura

Posted on

1

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

Top comments (0)

Image of Timescale

Timescale – the developer's data platform for modern apps, built on PostgreSQL

Timescale Cloud is PostgreSQL optimized for speed, scale, and performance. Over 3 million IoT, AI, crypto, and dev tool apps are powered by Timescale. Try it free today! No credit card required.

Try free

👋 Kindness is contagious

Engage with a sea of insights in this enlightening article, highly esteemed within the encouraging DEV Community. Programmers of every skill level are invited to participate and enrich our shared knowledge.

A simple "thank you" can uplift someone's spirits. Express your appreciation in the comments section!

On DEV, sharing knowledge smooths our journey and strengthens our community bonds. Found this useful? A brief thank you to the author can mean a lot.

Okay