1

我正在使用返回 unix 路径而不是 windows 路径的 acrobat。所以我想知道 vb.net 中是否有办法将路径转换为 ​​Windows 路径。

我尝试使用:

docs(i) = javaScriptObj.path().ToString.Replace("/", "\").Substring(1)
position = docs(i).IndexOf("\")
docs(i) = docs(i).Substring(0, position) + ":\" + docs(i).Substring(position + 1)

这仅适用于本地文件,但当我开始使用网络驱动器时失败。谢谢

4

1 回答 1

3

试试这个:

Private Function UnixPathToWindowsPath(UnixPath As String) As String
   If String.IsNullOrWhiteSpace(UnixPath) Then Return String.Empty
   Dim chunks = UnixPath.Split(New Char() {"/"c}, StringSplitOptions.RemoveEmptyEntries)
   If chunks.Any Then
      If chunks(0).Length = 1 Then 'Single character root, assume drive letter.
         Return String.Join("\", chunks).Insert(1, ":")
      Else
         Return "\\" & String.Join("\", chunks)
      End If
   Else
      Return IO.Path.DirectorySeparatorChar
   End If
End Function

这假定完整路径名,而不是部分路径。

于 2012-06-14T22:47:48.487 回答