Results 1 to 4 of 4

Thread: [2005] remove invalid characters from file name, regex ?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2001
    Location
    Austin
    Posts
    397

    [2005] remove invalid characters from file name, regex ?

    I need to remove these characters from the name of files in a folder. is regex the direction i need to go in?

    \ / : * ? " < > | # { } % ~ &

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,423

    Re: [2005] remove invalid characters from file name, regex ?

    it can be done with regex. i don't know how though.
    heres how to do it with string manipulation

    vb Code:
    1. Dim filename As String = "invalidFilename\/:*?" & Chr(34) & "<>|#{}%~&.txt"
    2. Dim invalidChars() As String = {"\", "/", ":", "*", "?", Chr(34), "<", ">", "|", "#", "{", "}", "%", "~", "&"}
    3. For x As Integer = 0 To invalidChars.GetUpperBound(0)
    4.      filename = filename.replace(invalidChars(x), "")
    5. Next
    6. filename = filename.Replace("in", "")
    7. MsgBox(filename)

  3. #3
    Frenzied Member
    Join Date
    Jul 2006
    Location
    MI
    Posts
    2,012

    Re: [2005] remove invalid characters from file name, regex ?

    You shouldn't even have to check for the first 9 characters you listed (\ / : * ? " < > |) as Windows won't allow filenames with those characters. The remaining characters are actually valid by Windows standards.

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2001
    Location
    Austin
    Posts
    397

    Re: [2005] remove invalid characters from file name, regex ?

    moving files to sharepoint...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width