MIB File rename script

MIB File rename script

Let me kick off by sharing a solution ;-)

I have created a windows vbs script to help you rename the MIB files to the names given in the MIB itself.

I noticed most vendors distribute MIB's but have the strange habbit to rename the files.

This script will fix this problem.

Enjoy,

Jilles Groenendijk

'* ========================================================================
'*
'* File         : MIB-renamer.vbs
'*
'* Version      : 1.01
'* Author       : Jilles Groenendijk ( Jilles@Jilles.com | @JillesDOTCOM)
'* Last Updated : 2012-03-16 1917
'* Purpose      : Rename MIB files to given name in File
'*
'* Changelog    : 1.00 - Intial Release
'*                1.01 - Added interaction for overwrite questions
'*
'* ========================================================================
'On Error Resume Next













If MsgBox("This script will rename all MIB files in this directory." & vbCrLf & vbCrLf & "Are you sure?", _
  vbYesNo + vbQuestion + vbDefaultButton2 + vbApplicationModal, _
  "MIB-renamer.vbs - by: Jilles Groenendijk") = vbYes Then
  nIgnored=0
  nRenamed=0
  nReplaced=0
  Set oFSO = CreateObject("Scripting.FileSystemObject")
  Set oFolder = oFSO.GetFolder(".\")







  For Each oFiles In oFolder.Files

    cFolder      = oFiles.ParentFolder
    cFilePath    = oFiles.Path 
    cNewFilePath = cFilePath

    If LCase(Right(cFilePath,3)) = "mib" Then

      Set oFile = oFSO.GetFile(cFilePath)

      If oFile.Size > 0 Then

        Set oFH = oFile.OpenAsTextStream(1)

        For i=1 To 20
          cLine = oFH.ReadLine
          If InStr(cLine ,"DEFINITIONS") > 0 Then
            cNewFileName = Trim( Mid( cLine, 1, InStr( cLine , "DEFINITIONS") -1) )
            cNewFilePath = cFolder & "\" & cNewFileName
       End If
        Next





        oFH.Close   
        Set oFH = Nothing

      End If

      Set oFile = Nothing

      If cFilePath <> cNewFilePath Then

       If oFSO.FileExists(cNewFilePath) Then
            If MsgBox("Destination File: " & vbCrLf & vbCrLf & cNewFileName & vbCrLf & vbCrLf & _
                "already exists, Do you want to overwrite this file?", _
                      vbYesNo + vbQuestion + vbDefaultButton2 + vbApplicationModal, _
                      "MIB-renamer.vbs - by: Jilles Groenendijk") = vbYes Then
        oFSO.DeleteFile cNewFilePath     
              oFSO.MoveFile cFilePath,cNewFilePath
     nReplaced=nReplaced+1
   Else 
     nIgnored=nIgnored+1
   End if 
  Else
          oFSO.MoveFile cFilePath,cNewFilePath  
         nRenamed=nRenamed+1
        End If
      End If














    End If

  Next

  MsgBox "Done!" & vbCrLf & vbCrLf &_
    nRenamed  & " File(s) renamed" & vbCrLf &_
    nReplaced & " File(s) replaced" & vbCrLf &_
    nIgnored & " File(s) ignored" & vbCrLf, _
    VbOKOnly + vbInformation + vbDefaultButton1 + vbApplicationModal, _
    "MIB-renamer.vbs - by: Jilles Groenendijk"




  Set oFolder = Nothing
  Set oFSO = Nothing
Else
  Wscript.Echo "Aborted!"


End If

 

                  New to ADSelfService Plus?