|
Each contribution is licensed to you under a License Agreement by its owner, not Microsoft. Microsoft does not guarantee the contribution or purport to grant rights to it.
|
Categories |
Remove Non-English Characters From File Names(Community)
Script Code
VBScript
' 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
Platforms
For online peer support, join
The Official Scripting Guys Forum!
To provide feedback or report bugs in sample scripts, please start a new discussion on the Discussions tab for this script.
Disclaimer
The sample scripts are not supported under any Microsoft standard support program or service. The sample scripts are provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.
Be the first to create a discussion.
|