Skip to main content

Diigo Home

Coder's Talk: VBScript to Replace Underscores in Filename with Spaces for All ... - The Diigo Meta page

coderstalk.blogspot.com/...to-replace-underscores-in.html - Cached - Annotated View

Jason Coleman's personal annotations on this page

ideadude
Ideadude bookmarked on 2009-04-13

Script to rename all files in a directory... to e.g. replace underscores with spaces... I altered to do the reverse.

  • '========================================================
    ' VBScript to replace underscore in file name with space
    ' for each files in a folder
    ' Written by ApOgEE of http://coderstalk.blogspot.com
    '========================================================
    Dim sName
    Dim fso
    Dim fol

    ' create the filesystem object
    Set fso = WScript.CreateObject("Scripting.FileSystemObject")

    ' get current folder
    Set fol = fso.GetFolder(".")

    ' go thru each files in the folder
    For Each fil In fol.Files
    ' check if the file name contains underscore
    If InStr(1, fil.Name, "_") <> 0 Then
    ' replace underscore with space
    sName = Replace(fil.Name, "_", " ")
    ' rename the file
    fil.Name = sName
    End If
    Next

    ' echo the job is completed
    WScript.Echo "Completed!"

This link has been bookmarked by 1 people . It was first bookmarked on 13 Apr 2009, by Jason Coleman.

  • 13 Apr 09
    ideadude
    Jason Coleman

    Script to rename all files in a directory... to e.g. replace underscores with spaces... I altered to do the reverse.

    • '========================================================
      ' VBScript to replace underscore in file name with space
      ' for each files in a folder
      ' Written by ApOgEE of http://coderstalk.blogspot.com
      '========================================================
      Dim sName
      Dim fso
      Dim fol

      ' create the filesystem object
      Set fso = WScript.CreateObject("Scripting.FileSystemObject")

      ' get current folder
      Set fol = fso.GetFolder(".")

      ' go thru each files in the folder
      For Each fil In fol.Files
      ' check if the file name contains underscore
      If InStr(1, fil.Name, "_") <> 0 Then
      ' replace underscore with space
      sName = Replace(fil.Name, "_", " ")
      ' rename the file
      fil.Name = sName
      End If
      Next

      ' echo the job is completed
      WScript.Echo "Completed!"