INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

VBScript Sharepoint path length and special character checker

VBScript Sharepoint path length and special character checker

VBScript Sharepoint path length and special character checker

(OP)
Hi guys,

New to the forums and looking for some assistance probably from an experienced VBScript programer. I'm looking to have a VBScript that runs on a folder that is selected by the user and runs on all subfolders checking the documents file path length to ensure it is under 256. This is the max characters acceptable in sharepoint. It also has been setup so that %20 is entered anywhere there is a space. Need it to check for special characters that sharepoint doesn't accept as well.

Below is the program, can't figure out what is wrong. Just won't seem to work on subfolders properly. Any assistance is greatly appreciated.

Full program uploaded here: http://files.engineering.com/getfile.aspx?folder=7...

CODE --> VBScript

Option Explicit
Private intLongestName As Integer
Private intCount As Integer
Sub processfolder()
    Dim strFldr As String
    Dim fso As Object

    intLongestName = 0
    Set fso = CreateObject("Scripting.FileSystemObject")
    strFldr = GetFolder
    If Len(strFldr) = 0 Then Exit Sub
    Process_folder fso, strFldr, True
    MsgBox "Process complete. " & CStr(intCount) & " files reviewed." & vbNewLine & vbNewLine & _
           "The longest file name is " & CStr(intLongestName) & " characters long." & vbNewLine & vbNewLine & _
           "The File Name and Path cannot exceed 255 characters."
End Sub

Sub Process_folder(fso As Object, strFldr As String, Optional blnResetCount As Boolean = False)
    Dim fldr As Object
    Dim fldrSub As Object
    Dim fl As Object

    Set fldr = fso.GetFolder(strFldr)
    intCount = 0
    For Each fl In fldr.Files
        intCount = intCount + 1
        If Len(fl.Name) > intLongestName Then
            intLongestName = Len(Replace(fl.Name, " ", "%20"))
            Debug.Print fl.Name
        End If
        ValidFileName fl.Name
    Next
    For Each fldrSub In fldr.SubFolders
        Process_folder fso, fldrSub.Path
    Next
End Sub

Sub protectFile()
    ActiveDocument.Protect wdAllowOnlyFormFields
End Sub


Function GetFolder() As String
    Dim fldr As FileDialog
    Dim sItem As String
    Set fldr = Application.FileDialog(msoFileDialogFolderPicker)
    With fldr
        .Title = "Select a Folder"
        .AllowMultiSelect = False
        .InitialFileName = "h:\"
        If .Show <> -1 Then GoTo NextCode
        sItem = .SelectedItems(1)
    End With
NextCode:
    GetFolder = sItem
    Set fldr = Nothing
End Function

Sub ValidFileName(strFile As String)
    Dim blnValidFile As Boolean
    blnValidFile = True
    If InStr(1, strFile, "~", vbTextCompare) > 0 Then
        MsgBox "The file name: " & strFile & " cannot have the Tilde (~) character when uploading to SharePoint.", vbCritical, "Check File Name"
        blnValidFile = False
    End If
    If InStr(1, strFile, "#", vbTextCompare) > 0 Then
        MsgBox "The file name: " & strFile & " cannot have the Number sign (#) character when uploading to SharePoint.", vbCritical, "Check File Name"
        blnValidFile = False
    End If
    If InStr(1, strFile, "%", vbTextCompare) > 0 Then
        MsgBox "The file name: " & strFile & " cannot have the Percent (%) character when uploading to SharePoint.", vbCritical, "Check File Name"
        blnValidFile = False
    End If
    If InStr(1, strFile, "&", vbTextCompare) > 0 Then
        MsgBox "The file name: " & strFile & " cannot have the Ampersand (&) character when uploading to SharePoint.", vbCritical, "Check File Name"
        blnValidFile = False
    End If
    If InStr(1, strFile, "*", vbTextCompare) > 0 Then
        MsgBox "The file name: " & strFile & " cannot have the Asterisk (*) character when uploading to SharePoint.", vbCritical, "Check File Name"
        blnValidFile = False
    End If
    If InStr(1, strFile, "{", vbTextCompare) > 0 Then
        MsgBox "The file name: " & strFile & " cannot have the Left Brace ({) character when uploading to SharePoint.", vbCritical, "Check File Name"
        blnValidFile = False
    End If
    If InStr(1, strFile, "}", vbTextCompare) > 0 Then
        MsgBox "The file name: " & strFile & " cannot have the Right Brace (}) character when uploading to SharePoint.", vbCritical, "Check File Name"
        blnValidFile = False
    End If
    If InStr(1, strFile, "\\", vbTextCompare) > 0 Then
        MsgBox "The file name: " & strFile & " cannot have the Double Backslash (\\) character when uploading to SharePoint.", vbCritical, "Check File Name"
        blnValidFile = False
    End If
    If InStr(1, strFile, ":", vbTextCompare) > 0 Then
        MsgBox "The file name: " & strFile & " cannot have the Colon (:) character when uploading to SharePoint.", vbCritical, "Check File Name"
        blnValidFile = False
    End If
    If InStr(1, strFile, "<", vbTextCompare) > 0 Then
        MsgBox "The file name: " & strFile & " cannot have the Left Angle brackets (<) character when uploading to SharePoint.", vbCritical, "Check File Name"
        blnValidFile = False
    End If
    If InStr(1, strFile, ">", vbTextCompare) > 0 Then
        MsgBox "The file name: " & strFile & " cannot have the Right Angle brackets (>) character when uploading to SharePoint.", vbCritical, "Check File Name"
        blnValidFile = False
    End If
    If InStr(1, strFile, "?", vbTextCompare) > 0 Then
        MsgBox "The file name: " & strFile & " cannot have the Question mark (?) character when uploading to SharePoint.", vbCritical, "Check File Name"
        blnValidFile = False
    End If
    If InStr(1, strFile, "/", vbTextCompare) > 0 Then
        MsgBox "The file name: " & strFile & " cannot have the Slash (/) character when uploading to SharePoint.", vbCritical, "Check File Name"
        blnValidFile = False
    End If
    If InStr(1, strFile, "+", vbTextCompare) > 0 Then
        MsgBox "The file name: " & strFile & " cannot have the Plus sign (+) character when uploading to SharePoint.", vbCritical, "Check File Name"
        blnValidFile = False
    End If
    If InStr(1, strFile, "|", vbTextCompare) > 0 Then
        MsgBox "The file name: " & strFile & " cannot have the Pipe (|) character when uploading to SharePoint.", vbCritical, "Check File Name"
        blnValidFile = False
    End If
    If InStr(1, strFile, Chr(34), vbTextCompare) > 0 Then
        MsgBox "The file name: " & strFile & " cannot have the Quotation mark (" & Chr(34) & ") character when uploading to SharePoint.", vbCritical, "Check File Name"
        blnValidFile = False
    End If

    blnValidFile = CheckFileName(strFile, ".Files", blnValidFile)
    blnValidFile = CheckFileName(strFile, "_files", blnValidFile)
    blnValidFile = CheckFileName(strFile, "-Dateien", blnValidFile)
    blnValidFile = CheckFileName(strFile, "_fichiers", blnValidFile)
    blnValidFile = CheckFileName(strFile, "_bestanden", blnValidFile)
    blnValidFile = CheckFileName(strFile, "_file", blnValidFile)
    blnValidFile = CheckFileName(strFile, "_archivos", blnValidFile)
    blnValidFile = CheckFileName(strFile, "-filer", blnValidFile)
    blnValidFile = CheckFileName(strFile, "_tiedostot", blnValidFile)
    blnValidFile = CheckFileName(strFile, "_pliki", blnValidFile)
    blnValidFile = CheckFileName(strFile, "_soubory", blnValidFile)
    blnValidFile = CheckFileName(strFile, "_elemei", blnValidFile)
    blnValidFile = CheckFileName(strFile, "_ficheiros", blnValidFile)
    blnValidFile = CheckFileName(strFile, "_arquivos", blnValidFile)
    blnValidFile = CheckFileName(strFile, "_dosyalar", blnValidFile)
    blnValidFile = CheckFileName(strFile, "_datoteke", blnValidFile)
    blnValidFile = CheckFileName(strFile, "_fitxers", blnValidFile)
    blnValidFile = CheckFileName(strFile, "_failid", blnValidFile)
    blnValidFile = CheckFileName(strFile, "_fails", blnValidFile)
    blnValidFile = CheckFileName(strFile, "_bylos", blnValidFile)
    blnValidFile = CheckFileName(strFile, "_fajlovi", blnValidFile)
    blnValidFile = CheckFileName(strFile, "_fitxategiak", blnValidFile)
End Sub
Function CheckFileName(strFileName As String, strTrailingtext As String, blnValid As Boolean) As Boolean
    If StrComp(Right(strFileName, Len(strTrailingtext)), strTrailingtext, vbTextCompare) = 0 Then
        MsgBox "The file name: " & strFileName & " cannot end with " & strTrailingtext & ".", vbCritical, "Check File Name"
        CheckFileName = False
        Exit Function
    End If
    CheckFileName = blnValid
End Function 

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close