Previous Topic

Next Topic

Book Contents

Book Index

Sample Script

The following script demonstrates custom directory parsing.

' This script parses a directory listing from a Windows FTP server. 
' In real life, this script would not be necessary, because 
' MOVEit Central is able to natively recognize and parse directory 
' listings on Windows FTP servers. 
' 
' A Windows FTP server returns a directory list like: ' 05-02-06 04:22PM 734 ModsNotes.txt 
' 10-13-05 09:13AM <DIR> Incoming 
' 123456789a123456789b123456789c123456789d123456789
' 
Option Explicit 
Sub Main() 
   Dim sDirListing, aryLines, MyLine, TestForDir, MyName, j 
   Dim MyYear, MyMonthDay, MyTime, MyDate, MySize, bIsDir, NFiles, NDirs sDirListing = MIDirGetListing() 
   ' Break apart the listing into an array of lines. 
   aryLines = Split(sDirListing, vbCrLf) 
   NFiles = 0 
   NDirs = 0 
   For j = LBound(aryLines) To UBound(aryLines) 
      MyLine = aryLines(j) 
      ' Heuristic to ignore any unreasonably short lines. 
      If Len(MyLine) > 39 Then 
         ' MOVEit Central doesn't understand mm-dd-yy format, 
         ' so change a date like 10-13-05 to 05-10-13. 
         MyMonthDay = Mid(MyLine, 1, 5) 
         MyYear = Mid(MyLine, 7, 2) 
         MyTime = Mid(MyLine, 11, 7) 
         MyDate = MyYear & "-" & MyMonthDay & " " & MyTime 
         MyName = Mid(MyLine, 40) 
         TestForDir = Mid(MyLine, 25, 5) 
         If TestForDir = "<DIR>" Then 
            bIsDir = True 
            MySize = 0 
            NDirs = NDirs + 1 
         Else 
            bIsDir = False 
            MySize = Mid(MyLine, 19, 38-19+1) 
            NFiles = NFiles + 1 
         End If 
         MIDirAddEntry MyName, MyDate, MySize, bIsDir, MyName, MyName 
      End If 
   Next 
   If MIGetDebugLevel() >= 50 Then 
      MILogMsg "Found " & NFiles & " files and " & NDirs & " dirs" 
   End If 
End Sub 

Main