The procedure below will change all file names to lower case. It will also clean up the file names. You will have to modify the code if you don't want all the cleanup characters to be revised.
If you want to update all of your hyperlinks to the new file names, you have to be using Expression Web's metadata files. Go to Site -> Site Settings -> General and check the box for "Manage the Web site using hidden metadata files."
The function below contains a list of characters that I wanted to eliminate from my file names. The characters I wanted to eliminate have a first element value of zero. The replacement character is always an underscore and are listed with the first element value of one.
arrPublic(0,0) is a blank space. The other characters I wanted to remove are: - ! $ & ( ) , . @ [ ] ^ ` { } ~ + and '.
Function SetBadCharacters() As Boolean
SetBadCharacters = False
ReDim arrPublic(1, 18)
arrPublic(0, 0) = " "
arrPublic(1, 0) = "_"
arrPublic(0, 1) = "-"
arrPublic(1, 1) = "_"
arrPublic(0, 2) = "!"
arrPublic(1, 2) = "_"
arrPublic(0, 3) = "$"
arrPublic(1, 3) = "_"
arrPublic(0, 4) = "&"
arrPublic(1, 4) = "_"
arrPublic(0, 5) = "("
arrPublic(1, 5) = "_"
arrPublic(0, 6) = ")"
arrPublic(1, 6) = "_"
arrPublic(0, 7) = ","
arrPublic(1, 7) = "_"
arrPublic(0, 8) = "."
arrPublic(1, 8) = "_"
arrPublic(0, 9) = "@"
arrPublic(1, 9) = "_"
arrPublic(0, 10) = "["
arrPublic(1, 10) = "_"
arrPublic(0, 11) = "]"
arrPublic(1, 11) = "_"
arrPublic(0, 12) = "^"
arrPublic(1, 12) = "_"
arrPublic(0, 13) = "`"
arrPublic(1, 13) = "_"
arrPublic(0, 14) = "{"
arrPublic(1, 14) = "_"
arrPublic(0, 15) = "}"
arrPublic(1, 15) = "_"
arrPublic(0, 16) = "~"
arrPublic(1, 16) = "_"
arrPublic(0, 17) = "+"
arrPublic(1, 17) = "_"
arrPublic(0, 18) = "'"
arrPublic(1, 18) = "_"
SetBadCharacters = True
End Function
The actual procedure is:
Sub CheckFileNames()
On Error GoTo errHandler1
Dim i As Long
Dim j As Long
Dim blnChanged As Boolean
Dim blnCapitalLetters As Boolean
Dim blnSpaces As Boolean
Dim strNewFileName As String
Dim objFile As WebFile
Dim objOldFile As WebFile
Dim intLastSlash As Integer
Dim strFileName As String
Dim strFullPathFileName As String
If Not SetBadCharacters Then GoTo errHandler1:
For i = 0 To WebDesigner.Application. _
ActiveWeb.AllFiles.Count - 1
Set objFile = _
Application.ActiveWeb.AllFiles.Item(i)
'Limit the files to htm files.
If objFile.Extension = "htm" Then
'put old file name in string variable
strFileName = Left(objFile.Name, _
Len(objFile.Name) - 4)
'set initial value of new file name _
'to old file name
strNewFileName = strFileName
'Process each letter in file name.
For j = 1 To Len(strNewFileName)
'Then process each element in array
For k = 0 To UBound(arrPublic, 2)
'if that chararcter is bad
If Mid(strNewFileName, j, 1) = _
arrPublic(0, k) Then
'replace it with underscore.
Mid(strNewFileName, j, 1) = _
arrPublic(1, k)
'It will not find another
'bad element, so exit.
Exit For
'Check for capital letter.
ElseIf _
(Asc(Mid(strNewFileName, j, 1)) > 64 _
And _
Asc(Mid(strNewFileName, j, 1)) < 91) _
Then
If j = 1 Then
'j=1 Example
' "Martha.htm" to "martha.htm"
strNewFileName = _
LCase(Mid(strNewFileName, 1, 1)) & _
Mid(strNewFileName, j + 1, _
Len(strNewFileName))
' j = j + 1
ElseIf j < Len(strNewFileName) Then
If _
(Asc(Mid(strNewFileName, _
j + 1, 1)) < 65 _
Or _
Asc(Mid(strNewFileName, _
j + 1, 1)) > 90 _
Or _
Mid(strNewFileName, _
j + 1, 1) = ".") Then
'Example change
' "MyFile.htm" to "my_file.htm" or
strNewFileName = _
Mid(strNewFileName, 1, j - 1) & _
"_" & _
LCase(Mid(strNewFileName, _
j, 1)) & Mid(strNewFileName, _
j + 1, Len(strNewFileName))
j = j + 1
Else
'Example
' "mYNEWPAGE.htm" to
'"mynewpage.htm"
strNewFileName = _
Mid(strNewFileName, 1, j - 1) & _
LCase(Mid(strNewFileName, _
j, 1)) & Mid(strNewFileName, _
j + 1, Len(strNewFileName))
End If
Else
'Example
' "abC.htm" to "abc.htm"
strNewFileName = _
Mid(strNewFileName, 1, j - 1) & _
LCase(Mid(strNewFileName, _
j, 1)) & Mid(strNewFileName, _
j + 1, Len(strNewFileName))
End If 'j=1
End If
Next k
Next j
'Change "my________mile.htm" to "my_file.htm"
Do Until InStr(1, strNewFileName, "__") = 0
strNewFileName = _
Replace(strNewFileName, "__", "_")
Loop
If strFileName <> strNewFileName Then
'give it a fake name
'this will revise the href property in
'pages that link to this file from
' "ABC.htm" to "xxxabc.htm"
strNewFileName = "xxx" & _
strNewFileName & ".htm"
objFile.Move strNewFileName, True, False
'then change from
'"xxxabc.htm" to "abc.com"
'changing file name directly from
'"ABC.htm" to "abc.htm" will not update
'href to lowercase.
strNewFileName = _
Mid(strNewFileName, 4, Len(strNewFileName))
objFile.Move strNewFileName, True, False
End If
End If 'strExt = "htm"
Next i
Exit Sub
errHandler1:
MsgBox _
"Err.Number: " & Err.Number & vbCrLf & _
"Err.Description: " & Err.Description, _
vbCritical, "GetQualifiedFileNames Function " & _
"had a Fatal Error."
End Sub
Sample file name before running procedure:
Mr. and Mrs. Nelson's (Clarence & Judy) Farm.htm
Sample file name after running procedure.
mr_and_mrs_nelson_s_clarence_judy_farm.htm
I actually prefer the first name, but I'm just asking for trouble from some browser or another if I keep using it. I am also guessing that future versions of XHTML are likely to not allow some of my old file names.