在VB中,可以使用System.IO.Path类的GetDirectoryName方法来获取文件所在路径。示例如下:
Dim filePath As String = "C:\Users\Example\Documents\sample.txt"
Dim directoryPath As String = System.IO.Path.GetDirectoryName(filePath)
Console.WriteLine("File path: " & filePath)
Console.WriteLine("Directory path: " & directoryPath)
上面的代码将输出以下结果:
File path: C:\Users\Example\Documents\sample.txt
Directory path: C:\Users\Example\Documents
这样就可以获取到文件所在的路径。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读:linux怎么获取文件所在路径