
Dim SourceDir
Dim DestDir
Dim SourceExt
Dim DestExt

Const MB_STATUS_BAR=6

SourceDir="c:\source\"
DestDir="c:\dest\"
SourceExt="ngs"
DestExt="tsf"
IncludeSubDir=1

' Restore saved parameters
SetConfig

' Set FileSystem
set filesystem = createobject("Scripting.FileSystemObject")
Set p = FileSystem.GetFolder(SourceDir)

' Look for Files to convert
For Each dataFile In p.Files
   Convert dataFile
Next

if IncludeSubDir=1 then ConvertSubFolders (p)

LabSpec.Message "Convertion Done.",MB_STATUS_BAR

' Look for Files to convert in subfolders
Private Sub ConvertSubFolders(MainFolder)

    dim FolderToCreate
    For Each folder In MainFolder.SubFolders
        ' Create Destination subfolder if it does not exist
        FolderToCreate=DestDir & right(folder,len(folder)-len(SourceDir))
        If Not filesystem.FolderExists(FolderToCreate) then filesystem.CreateFolder  FolderToCreate
        
        ' Look for Files to convert
        For Each dataFile In folder.Files
            Convert dataFile
        Next
        Call ConvertSubFolders(folder)
    Next

end sub

' Convert File
Private Sub Convert(dataFile)
 
 	dim Pos
	dim FileManePos
	Dim FileName
	dim Param

        'Check File Type
        if right(dataFile,len(SourceExt))=SourceExt then

          ' Manage File Names and Directories
          FileName=right(dataFile,len(dataFile)-len(SourceDir))
          FileName=left(FileName,len(FileName)-len(SourceExt)-1)

  	  DestFileName=DestDir & FileName & "." & DestExt
  	  
  	  LabSpec.Message "Converting " & dataFile & " to " &  DestFileName,MB_STATUS_BAR

          ' Load and save file
  	  ID=LabSpec.Load(dataFile)
  	  LabSpec.Save ID,DestFileName,DestExt

        End If

end sub

' Manage parameters
Private Sub SetConfig()

        LabSpec.SetSingleScriptParam "Source Dir","folder",SourceDir,PARAM_DEFAULT
        LabSpec.SetSingleScriptParam "Source Ext","file ext.",SourceExt,PARAM_DEFAULT
        LabSpec.SetSingleScriptParam "Dest Dir","folder",DestDir,PARAM_DEFAULT
        LabSpec.SetSingleScriptParam "Dest Ext","file ext.",DestExt,PARAM_DEFAULT
        LabSpec.SetSingleScriptParam "Sub Directories","0-No 1-Yes",IncludeSubDir,PARAM_DEFAULT

        LabSpec.SetScriptParamOptions "File Converter",1

        LabSpec.SetSingleScriptParam "Source Dir","folder",SourceDir,PARAM_DEFAULT
        LabSpec.SetSingleScriptParam "Source Ext","file ext.",SourceExt,PARAM_DEFAULT
        LabSpec.SetSingleScriptParam "Dest Dir","folder",DestDir,PARAM_DEFAULT
        LabSpec.SetSingleScriptParam "Dest Ext","file ext.",DestExt,PARAM_DEFAULT
        LabSpec.SetSingleScriptParam "Sub Directories","0-No 1-Yes",IncludeSubDir,PARAM_DEFAULT

End Sub
