option explicit
Dim videosPath
Dim basePath
Dim currentVideoFile
Dim contentPath
Dim captionTextFile

'----------------------------------------------------------------------------------------------------

'
' Configuration
' Define the folders and files
' The folders and files must exist, so that Scala works
  basePath = "C:\Users\Public\Documents\Scala\Content"
  videosPath = "E:\mov"
  captionTextFile = basePath & "\sixtythousandlines.txt"
  contentPath = "C:\Users\Public\Documents\Scala\Content" 'captionTextFile contains captions for images
  currentVideoFile = "currentVideo.mov"
'----------------------------------------------------------------------------------------------------

Const ForReading = 1
Const ForWriting = 2

Dim fileSystemObject
Dim currentImageNumberFileName
Dim currentImageNumber
Dim currentImageNumberTextStream
Dim imageFileName

Dim currentCaptionTextStream
Dim currentCaption

Call copyVideoToContentFolder()
Call getImageCaption()

Sub copyVideoToContentFolder()
        Set fileSystemObject = CreateObject("Scripting.FileSystemObject")

        currentImageNumberFileName = videosPath & "\Current Image Number.txt"

        If fileSystemObject.FileExists(currentImageNumberFileName) Then
          Set currentImageNumberTextStream = fileSystemObject.OpenTextFile(currentImageNumberFileName, ForReading)
          currentImageNumber = CInt(currentImageNumberTextStream.ReadLine)
        Else
          currentImageNumber = 1
          Set currentImageNumberTextStream = fileSystemObject.CreateTextFile(currentImageNumberFileName, True)
          currentImageNumberTextStream.WriteLine(CStr(1))
        End If

        currentImageNumberTextStream.Close
        imageFileName = videosPath & "\" & CStr(currentImageNumber) & ".mov" 
        Dim outputImagePath
        
        If Not fileSystemObject.FileExists(imageFileName) Then
          currentImageNumber = 1
          imageFileName = videosPath & "\" & CStr(currentImageNumber) & ".mov"
        End If
        
        outputImagePath = contentPath & "\" & currentVideoFile
        Call fileSystemObject.CopyFile(imageFileName, outputImagePath, True)
        imageNumber = currentImageNumber
End Sub

Sub getImageCaption()
        Set currentCaptionTextStream = fileSystemObject.OpenTextFile(captionTextFile, ForReading)

        Dim k
        k = 1
        While k < currentImageNumber
         currentCaptionTextStream.SkipLine
         k = k + 1
        WEnd
        currentCaption = currentCaptionTextStream.ReadLine
        'caption is shared variable created in scala
        caption = currentCaption
        currentCaptionTextStream.Close

        currentImageNumber = currentImageNumber + 1
        REM imageFileName = videosPath & "\" & CStr(currentImageNumber) & ".mov"

        Set currentImageNumberTextStream = fileSystemObject.OpenTextFile(currentImageNumberFileName, ForWriting, True)
          currentImageNumberTextStream.WriteLine(CStr(currentImageNumber))
        currentImageNumberTextStream.Close
End Sub