LastWriteTime of directory

Advertisement

MrRobot
Joined:
Posts:
1

LastWriteTime of directory

Hey there,

I want to select all remote subfolders with a specific LastWriteTime, in this case later than yesterday. I don't want to select the files in the folders, just the folder itself.
$mask = "*>=yesterday"
$files =
   $session.EnumerateRemoteFiles(
      $remotePath, $mask, [WinSCP.EnumerationOptions]::MatchDirectories) |
   Select-Object -ExpandProperty FullName               
echo $files
This does not work. Any idea on how to make this work?

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
41,517
Location:
Prague, Czechia

Re: LastWriteTime of directory

The Session.EnumerateRemoteFiles supports only trivial file masks, definitely not time constraints.

You have to use RemoteFileInfo.LastWriteTime to select the desired folders:
$limit = [System.DateTime]::Today.AddDays(-1)
$opts =
    [WinSCP.EnumerationOptions]::AllDirectories -bor
    [WinSCP.EnumerationOptions]::EnumerateDirectories
$files =
     $session.EnumerateRemoteFiles(
         $remotePath, $Null, $opts) |
     Where-Object { $_.IsDirectory -and ($_.LastWriteTime -gt $limit) } |
     Select-Object -ExpandProperty FullName

Reply with quote

Advertisement

You can post new topics in this forum