Set oFSO = CreateObject("Scripting.FileSystemObject")
oVidFolder = "ProClips" 'Video Recording Directory for WitnessPro
oDestFolder = "C:\Snapshots" 'Where the snapshots are kept
'Find the full path of oVidFolder
for each drive in fso.drives
if drive.IsReady then
oVidPath = drive.DriveLetter & ":\" & oVidFolder
if fso.folderexists(oVidPath) then
'Find the newest file in each subfolder of oVidPath
ShowSubfolders oFSO.GetFolder(oVidPath)
end if
end if
next
'This is the function that finds the newest file in the folder
Function GetNewestFile(ByVal oFolder)
sNewestFile = Null ' init value
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFolder = oFSO.GetFolder(oFolder)
Set oFiles = oFolder.Files
' enumerate the files in the folder, finding the newest file
For Each oFile In oFiles
On Error Resume Next
If IsNull(sNewestFile) Then
sNewestFile = oFile.Path
dPrevDate = oFile.DateLastModified
Elseif dPrevDate < oFile.DateLastModified Then
sNewestFile = oFile.Path
dPrevDate = oFile.DateLastModified
End If
On Error Goto 0
Next
If IsNull(sNewestFile) Then sNewestFile = ""
GetNewestFile = sNewestFile
End Function
Sub ShowSubFolders(Folder)
For Each Subfolder in Folder.SubFolders
Set oFolder = oFSO.GetFolder(Subfolder.Path)
sNewestFile = GetNewestFile(oFolder)
sFName = oFSO.GetBaseName(sNewestFile)
Set oShell = CreateObject("WScript.Shell")
sShellCmd = "c:\windows\ffmpeg -i " & sNewestFile & " -y -f mjpeg -s 320x240 -vframes 1 " & oDestFolder & sFName & ".jpg"
oShell.run(sShellCmd)
showSubFolders Subfolder
Next
End Sub