Announcement

Collapse
No announcement yet.

random file selection

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    random file selection

    greetings,

    i thought i was a good vb programmer until i tried to write a script in homeseer.

    i just want to grab an array of the files in a given directory, select one at random and copy it to the html directory.

    (yes, this is for HStouch to use as a slide show)



    everything i've tried i've ended up with one error or another, i'm lost, and ready to increase my alcohol consumption

    thanks

    #2
    In the weatherXML plugin I use vb.nets directoryInfo and fileInfo to get a list of all the script files in the HS script directory to build a dropdown.
    PHP Code:
    Dim di As DirectoryInfo
    Dim diar1 
    As FileInfo()
    Dim dra As FileInfo
     
    di 
    = New IO.DirectoryInfo(fullPathway to your directory)
    diar1 di.GetFiles()
    dd = New clsJQuery.jqDropList(sDdNamepageNameFalse)
    dd.AddItem("No Script"""sSel "")
    For 
    Each dra In diar1
    If dra.Extension.ToLower ".vb" Or dra.Extension.ToLower ".txt" Then
    dd
    .AddItem(dra.Namedra.Namedra.Name sSel.Trim)
    End If
    Next
    s
    .Append(dd.Build
    You should be able to modify this and use diar1 as your array.. Once you have a random picture selected you can use File.Copy to copy it to the html directory.
    --
    Jeff Farmer
    HS 3, HSPhone
    My HS3 Plugins: CFHSExtras, Random, Restart, Tracker, WeatherXML, PanaBluRay
    Other Plugins In Use: APCUPSD, BLOnkyo, Device History, EasyTrigger, HSTouch Server, PHLocation2, Pushover, RFXCom, UltraGCIR3, UltraMon3, UltraPioneerAVR3, X10, Z-Wave

    Hardware: GoControl Irrigation Controler, Schlage Lever Lock, Schlage Deadbolt, Way2Call Hi-Phone, RFXCom RFXrec433 Receiver, WGL 800, TI-103, Z-Net, Pioneer 1120, Pioneer 1021, Pioneer LX302, Panasonic BDT-110, Panasonic BDT-210 x2

    Comment


      #3
      errors out....

      Code:
      imports system.io
      
      sub main
          hs.WriteLog "Error", "Hello World"
          sourcedir= "E:\Source\hs3\pics"
      
      Dim di As DirectoryInfo 
      Dim diar1 As FileInfo() 
      Dim dra As FileInfo 
        
      di = New IO.DirectoryInfo(sourcedir) 
      diar1 = di.GetFiles() 
      dd = New clsJQuery.jqDropList(sDdName, pageName, False) 
      dd.AddItem("No Script", "", sSel = "") 
      
      dir_count = 0
      
      For Each dra In diar1 
      If dra.Extension.ToLower = ".png" Or dra.Extension.ToLower = ".jpg" Then 
      dir_count = dir_count + 1
      dd.AddItem(dra.Name, dra.Name, dra.Name = sSel.Trim) 
      End If 
      Next 
      s.Append(dd.Build) 
      
      hs.WriteLog "Error", "Number of files: " & dir_count 
      
      end sub
      error

      Code:
      Expected end of statement in line 7 More info: Expected end of statement

      Comment


        #4
        I have only been working in plugins but clsjquery items needs the following

        Imports Scheduler


        but with what you are wanting to do you can remove the dropdown and just use the array.
        PHP Code:
        di = New IO.DirectoryInfo(fullPathway to your directory
        diar1 di.GetFiles() 
        Dim nFiles As Int16 diar1.GetUpperBound(0)
        ' Get your random number.
        Dim filename as string = diar1(rndNumber).ToString 
        That should give you what you said you are wanting. An array of the files. nFiles should give you the number of files in the directory.
        Select a number between 0 and nFiles
        You can then use File.Copy to move the random file.

        Make sure that you replace
        ' Get your random number.
        with some code that gets a random number between 0 and nFiles
        --
        Jeff Farmer
        HS 3, HSPhone
        My HS3 Plugins: CFHSExtras, Random, Restart, Tracker, WeatherXML, PanaBluRay
        Other Plugins In Use: APCUPSD, BLOnkyo, Device History, EasyTrigger, HSTouch Server, PHLocation2, Pushover, RFXCom, UltraGCIR3, UltraMon3, UltraPioneerAVR3, X10, Z-Wave

        Hardware: GoControl Irrigation Controler, Schlage Lever Lock, Schlage Deadbolt, Way2Call Hi-Phone, RFXCom RFXrec433 Receiver, WGL 800, TI-103, Z-Net, Pioneer 1120, Pioneer 1021, Pioneer LX302, Panasonic BDT-110, Panasonic BDT-210 x2

        Comment


          #5
          Code:
          Dim di As DirectoryInfo
          seems to be causing the error, not sure why?!?! i'm importing system.io

          Comment

          Working...
          X