Illegal characters in path

Posted MessageBox

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Illegal characters in path相关的知识,希望对你有一定的参考价值。

 

 

 

执行ClearInvalidChars后,清除完成!

 

 

 public static string ClearInvalidChars(string fullname) {

            var source = fullname;
            char[] cp = new char[] { \'\\u002A\', \'\\u003A\', \'\\u003F\',\'\\u0022\',\'\\u003C\', \'\\u003E\', \'\\u007C\' };
            var root = fullname.Substring(0, fullname.IndexOf(":")+1);
            var relative = fullname.Substring(fullname.IndexOf(":")+1, fullname.Length- fullname.IndexOf(":")-1);
            foreach (var c in cp)
            {
                relative = relative.Replace(c.ToString(), "_");
            }
            fullname = root + relative;
            var chars = Path.GetInvalidPathChars();
            foreach (var c in chars)
            {
                fullname = fullname.Replace(c.ToString(), "_");
            }
            chars = Path.GetInvalidFileNameChars();
            var path = Path.GetDirectoryName(fullname);
            var filename = Path.GetFileName(fullname);
            foreach (var c in chars)
            {
                filename = filename.Replace(c.ToString(), "_");
            }
            return Path.Combine(path, filename);
        }

  

以上是关于Illegal characters in path的主要内容,如果未能解决你的问题,请参考以下文章

JavaJava URLDecoder异常Illegal hex characters in escape (%)

java.lang.IllegalArgumentException: Illegal character in query at index

curl 错误 [globbing] illegal character in range specification at pos

调用Http get 接口报错:java.lang.IllegalArgumentException: Illegal character in query at index 解决办法

URLDecoder: Illegal hex characters in escape (%) pattern - For input string

VS2017 v15.8.0 Task ExpandPriContent failed. Illegal characters in path