Results 1 to 10 of 10

Thread: remove illegal characters for path

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2007
    Posts
    128

    remove illegal characters for path

    i am using unrar.ocx and getting the filename extracted from it which i am using to move the file extracted to another folder but i am getting the error
    "illegal characters found in path"!!!! i debugged it.. what i found was weird is the filename variable have value:

    "c:\temp\myfile.txt

    with not quote at the end.... my question is ..is there a way to remove all illegal characters in a path to make it correct???

  2. #2
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: remove illegal characters for path

    Perhaps there isa better way but the following will work:
    VB Code:
    1. Private Function CheckAndClean(ByVal StringToCheck As String) As String
    2.         '=======================================================================
    3.         'purpose: Eliminate characters that are not allowed in file/folder name
    4.         '=======================================================================
    5.         Dim sIllegal As String = "\,/,:,*,?," & Chr(34) & ",<,>,|"
    6.         Dim arIllegal() As String = Split(sIllegal, ",")
    7.         Dim sReturn As String
    8.  
    9.         sReturn = StringToCheck
    10.  
    11.         For i = 0 To arIllegal.Length - 1
    12.             sReturn = Replace(sReturn, arIllegal(i), "")
    13.         Next
    14.  
    15.         Return sReturn
    16.  
    17.     End Function

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jan 2007
    Posts
    128

    Re: remove illegal characters for path

    oh it's not working still getting "illegal characters in path"... although when i msgbox the path... i find it ok...no special characters whatsoever

  4. #4
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: remove illegal characters for path

    Are you copying/moving a file? If so, there is two paths, one source and one destination, have you checked both?
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  5. #5

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Jan 2007
    Posts
    128

    Re: remove illegal characters for path

    checked both..see the pics... i find it very weird!!!

    edit: preparing some samples....
    Attached Images Attached Images   

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Jan 2007
    Posts
    128

    Re: remove illegal characters for path

    here is a sample
    - choose the .rar file
    - select a file extracted from the listbox
    - press "copy selected to" to copy selected file to directory of textbox...

    i hope you find out wat's wrong...
    Attached Files Attached Files

  8. #8
    Frenzied Member
    Join Date
    Mar 2006
    Location
    Pennsylvania
    Posts
    1,069

    Re: remove illegal characters for path

    jesus christ dude just add a " to the end of the filename...

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Jan 2007
    Posts
    128

    Re: remove illegal characters for path

    hmmm... does it work??!? i already tried it... this doesn't work!!!

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    Jan 2007
    Posts
    128

    Re: remove illegal characters for path

    ok i think i found the solution.. here it is

    i noticed e.g. if i have a file named "myfile.txt" ... and when i copy it to a directory, i get the illegal characters error.... and i see that the source file path is "c:\myfile.txt without the quote at the end... so that made me think that the illegal stuff is after the ".txt" ..somekind of weird illegal invisible characters... so i made this function...

    VB Code:
    1. Private Function cleanuppath(ByVal mypath, ByVal fileextension)
    2.         cleanuppath = mypath.ToString.ToLower.Substring(0, InStr(mypath, fileextension) + Len(fileextension) - 1)
    3.     End Function

    this just remove everything found after "c:\myfile.txt"... so the illegal invisible characters are removed... i don't really know why it is like that ..probably that the .ocx was meant primarily for vb6 and not vb.net

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