Submitted By: Walter Touceda

Removes non-English file characters from the names of all the files in a specified folder.

Visual Basic
Edit|Remove
' Created By Walter Touceda
' This script will remove all non-English characters in 
' all File Names in a specific folder (WINDOWS ONLY)
' It assumes a format like C:\temp\my folder\file name.ext
'
On Error Resume Next
i = 0
' Ask for full path
Do While i = 0
    strAnswer = InputBox _
        ("Please enter the path (e.g.: C:\temp\)","Clean File Names")
    If strAnswer = "" Then
        MsgBox "You must enter a path. Press OK to finish"
 Wscript.Quit
    Else
 If objFSO.FolderExists(strAnswer) Then
         Exit Do
 Else
  MsgBox "This folder does not exist: " & strAnswer
 End If
    End If
Loop
 
' In MyPath don't forget to include the last \
If Right(strAnswer,1) = "\" then
 MyPath = strAnswer
Else
 MyPath = strAnswer + "\"
End If
 
Set objFSO = CreateObject("Scripting.FileSystemObject")      
' Create FSO
Set objFolder = objFSO.GetFolder(MyPath) 
 
'Process every file in the Folder
For Each objItem in objFolder.Files
 Wscript.Echo "--------------------------"
 Wscript.Echo "Checking: " & objItem.Name
 ' Preserve Original Filename
 OriName = objItem.Name
 ' Start with blank new FileName
 FileName = ""
 
 ' Check Original FileName character by character
 For i = 1 To Len(OriName)
  MyCh = Mid(OriName, i, 1)
         If (MyCh >= " ") And (MyCh <= "~") Then
   ' Build FileName with English Characters Only
   FileName = FileName + MyCh
  Else
   ' This is a non-English character, ignore it
   ' Don't include it in new FileName
  End if
 Next
 OriName = MyPath & OriName
 FileName = MyPath & Filename
 If OriName = Filename then
  ' Filename was all-English, no need to rename
 Else
  ' Remove spaces at the end of the FileName
  ' Filename includes the extension, so do not include it
  Aux = Len(FileName) - 4
  Filename = Trim(Left(FileName,Aux))
  ' Keep same extension
  FileName = Filename + Right(OriName,4)
  Wscript.Echo "Renaming file : " & OriName
  Aux = objFSO.MoveFile(OriName, FileName)
  If Aux = 0 Then
   Wscript.Echo "Renamed to    : " & FileName
  Else
   Wscript.Echo "** Failed to rename: " & OriName
  End If
 End If
Next
 
' Clean memory and quit
Set OriName = Nothing
Set FileName = Nothing
Set MyCh = Nothing
Set Aux = Nothing
Set objFSO = Nothing
Set objFolder = Nothing
Set strAnswer = Nothing
Wscrip.Quit