logo

Live Production Software Forums


Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

2 Pages<12
Options
Go to last post Go to first unread
Ario  
#21 Posted : Tuesday, December 27, 2022 6:07:17 AM(UTC)
Ario

Rank: Advanced Member

Groups: Registered
Joined: 2/2/2015(UTC)
Posts: 166
Location: NL

Thanks: 164 times
Was thanked: 19 time(s) in 16 post(s)
+1
So many +1's ... am I right that this request was never implemented?
It deserves serious consideration.
PeterH  
#22 Posted : Wednesday, December 28, 2022 11:50:30 PM(UTC)
PeterH

Rank: Advanced Member

Groups: Registered
Joined: 5/25/2018(UTC)
Posts: 73

Was thanked: 6 time(s) in 6 post(s)
+1
jip  
#23 Posted : Tuesday, February 28, 2023 5:33:26 AM(UTC)
jip

Rank: Advanced Member

Groups: Registered
Joined: 7/23/2013(UTC)
Posts: 122
Estonia
Location: North

Thanks: 12 times
Was thanked: 13 time(s) in 11 post(s)
+1
melody  
#24 Posted : Wednesday, March 1, 2023 2:27:31 AM(UTC)
Guest

Rank: Guest

Groups: Guests
Joined: 1/13/2010(UTC)
Posts: 230

Was thanked: 3 time(s) in 3 post(s)
+1
avsoundguy  
#25 Posted : Wednesday, March 1, 2023 5:43:54 AM(UTC)
avsoundguy

Rank: Advanced Member

Groups: Registered
Joined: 10/26/2016(UTC)
Posts: 80

Thanks: 194 times
Was thanked: 13 time(s) in 12 post(s)
+1
WaltG12  
#26 Posted : Wednesday, March 1, 2023 6:06:22 PM(UTC)
WaltG12

Rank: Advanced Member

Groups: Registered
Joined: 7/4/2021(UTC)
Posts: 309
United States

Thanks: 8 times
Was thanked: 40 time(s) in 35 post(s)
+1

Originally Posted by: Ario Go to Quoted Post
+1
So many +1's ... am I right that this request was never implemented?
It deserves serious consideration.


Just because an idea--especially a popular one--has not been implemented doesn't mean it hasn't been (or isn't being) seriously considered.
jpratchett  
#27 Posted : Thursday, May 11, 2023 11:55:00 PM(UTC)
jpratchett

Rank: Member

Groups: Registered
Joined: 8/26/2017(UTC)
Posts: 10
Man
Location: UK

Was thanked: 4 time(s) in 3 post(s)
+1
RichDanby  
#28 Posted : Friday, May 12, 2023 3:16:28 AM(UTC)
RichDanby

Rank: Advanced Member

Groups: Registered
Joined: 2/23/2019(UTC)
Posts: 135
United Kingdom

Thanks: 16 times
Was thanked: 28 time(s) in 25 post(s)
This sounded like an interesting challenge so I've just written a PowerShell script that will monitor a folder and add new files to a list input - it doesn't handle files being deleted or renamed. I say I wrote it but it is 90% from a file monitoring example I found.

At the top of the code you need to set the input number of the list you want files added to and also the path to the folder you want to monitor.

To run it, open Windows PowerShell, and paste the script in and press enter. It outputs a . every second to show it is doing something and will display a message when a new file is found.

Hopefully this helps some of you out, or can be a starting point.

Code:

# values to set

# specify input you want the files added to
$ListInput=2

# specify the path to the folder you want to monitor: 
$Path = "C:\WatchFolder"

# specify which files you want to monitor
$FileFilter = '*'  

# specify whether you want to monitor subfolders as well:
$IncludeSubfolders = $false

#
#
#

# create TCP connection to vMix API
$tcpConnection = New-Object System.Net.Sockets.TcpClient(127.0.0.1, 8099)
$tcpStream = $tcpConnection.GetStream()
$writer = New-Object System.IO.StreamWriter($tcpStream)
$writer.AutoFlush = $true


# folder monitoring coded based on https://powershell.one/tricks/filesystem/filesystemwatcher#advanced-mode-asynchonous

$AttributeFilter = [IO.NotifyFilters]::FileName, [IO.NotifyFilters]::LastWrite 

try
{
  $watcher = New-Object -TypeName System.IO.FileSystemWatcher -Property @{
    Path = $Path
    Filter = $FileFilter
    IncludeSubdirectories = $IncludeSubfolders
    NotifyFilter = $AttributeFilter
  }

  # define the code that should execute when a change occurs:
  $action = {
    # the code is receiving this to work with:
    
    # change type information:
    $details = $event.SourceEventArgs
    $Name = $details.Name
    $FullPath = $details.FullPath
    $OldFullPath = $details.OldFullPath
    $OldName = $details.OldName
    
    # type of change:
    $ChangeType = $details.ChangeType
    
    # when the change occured:
    $Timestamp = $event.TimeGenerated
    
    # now you can define some action to take based on the
    # details about the change event:
    
    # let's compose a message:
    $text = "{0} was {1} at {2}" -f $FullPath, $ChangeType, $Timestamp
    Write-Host ""
    Write-Host $text -ForegroundColor DarkYellow
    
    # you can also execute code based on change type here:
    switch ($ChangeType)
    {
      'Changed'  { "CHANGE" }
      'Created'  { "CREATED"
        # add file to list
        $command = "FUNCTION ListAdd Input={0}&Value={1}" -f $ListInput, $FullPath
        $writer.writeLine($command)
        }
      'Deleted'  { "DELETED" }
      'Renamed'  { "RENAMED" }
        
      # any unhandled change types surface here:
      default   { Write-Host $_ -ForegroundColor Red -BackgroundColor White }
    }
  }

  # subscribe your event handler to all event types that are
  # important to you. Do this as a scriptblock so all returned
  # event handlers can be easily stored in $handlers:
  $handlers = . {
    Register-ObjectEvent -InputObject $watcher -EventName Changed  -Action $action 
    Register-ObjectEvent -InputObject $watcher -EventName Created  -Action $action 
    Register-ObjectEvent -InputObject $watcher -EventName Deleted  -Action $action 
    Register-ObjectEvent -InputObject $watcher -EventName Renamed  -Action $action 
  }

  # monitoring starts now:
  $watcher.EnableRaisingEvents = $true

  Write-Host "Watching for changes to $Path"

  # since the FileSystemWatcher is no longer blocking PowerShell
  # we need a way to pause PowerShell while being responsive to
  # incoming events. Use an endless loop to keep PowerShell busy:
  do
  {
    # Wait-Event waits for a second and stays responsive to events
    # Start-Sleep in contrast would NOT work and ignore incoming events
    Wait-Event -Timeout 1

    # write a dot to indicate we are still monitoring:
    Write-Host "." -NoNewline
        
  } while ($true)
}
finally
{
  # this gets executed when user presses CTRL+C:
  
  # stop monitoring
  $watcher.EnableRaisingEvents = $false
  
  # remove the event handlers
  $handlers | ForEach-Object {
    Unregister-Event -SourceIdentifier $_.Name
  }
  
  # event handlers are technically implemented as a special kind
  # of background job, so remove the jobs now:
  $handlers | Remove-Job
  
  # properly dispose the FileSystemWatcher:
  $watcher.Dispose()
  
  Write-Warning "Event Handler disabled, monitoring ends."
}
Users browsing this topic
Guest
2 Pages<12
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.