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???
Re: remove illegal characters for path
Perhaps there isa better way but the following will work:
VB Code:
Private Function CheckAndClean(ByVal StringToCheck As String) As String
'=======================================================================
'purpose: Eliminate characters that are not allowed in file/folder name
'=======================================================================
Dim sIllegal As String = "\,/,:,*,?," & Chr(34) & ",<,>,|"
Dim arIllegal() As String = Split(sIllegal, ",")
Dim sReturn As String
sReturn = StringToCheck
For i = 0 To arIllegal.Length - 1
sReturn = Replace(sReturn, arIllegal(i), "")
Next
Return sReturn
End Function
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
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?
Re: remove illegal characters for path
How do you get original string (the path)? Can you post few samples other than what you already did? There could be a null char (Chr(0)) which you need to replace as well.
2 Attachment(s)
Re: remove illegal characters for path
checked both..see the pics... i find it very weird!!!
edit: preparing some samples....
1 Attachment(s)
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...
Re: remove illegal characters for path
jesus christ dude just add a " to the end of the filename...
Re: remove illegal characters for path
hmmm... does it work??!? i already tried it... this doesn't work!!!
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:
Private Function cleanuppath(ByVal mypath, ByVal fileextension)
cleanuppath = mypath.ToString.ToLower.Substring(0, InStr(mypath, fileextension) + Len(fileextension) - 1)
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