如何在vb.net中获取文件名的路径 [英] How to get path of filename in vb.net

查看:853
本文介绍了如何在vb.net中获取文件名的路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数据库文件Main.mdb ....

这个文件可以放在计算机上的任何地方。我需要找到这个文件的代码并获取这个文件的路径。任何人都可以请帮帮我?

解决方案

如果你不知道文件在哪里,那你就做了些傻事 - 也就是忘记记下文件的位置你有它最后 - 除了到处寻找你别无选择。

这很复杂,因为你需要遍历根文件夹下的所有目录(而不是试图查看和文件在根目录中,因为它将抛出异常)并在所有这些上使用Directory.GetFiles。这将花费相当长的时间在普通磁盘上,并且几乎肯定会抛出您必须处理的访问冲突异常。



更好的方法是询问用户,或以某种方式记住它,这样你就不必搜索它。

.NET中没有在此磁盘上找到此文件方法


首先应该知道要google什么,抱歉我们不能真正教谷歌如何谷歌没有书可用



浏览以下链接,这可能会解决您的问题。



http://stackoverflow.com/questions/1225294/c-sharp-find-a-file-within-all-possible-folders [ ^ ]

I have a database file Main.mdb....
This file can be located anywhere on computer.I need code that finds this file and get path to this file..Can any one please help me?

解决方案

If you don't know where the file is, then you have done something silly - i.e. forgotten to make a note of where it is when you had it last - and you have no alternative except to look everywhere.
This is complicated because you will need to loop through all the directories off the root folder (without trying to look at and of the file in the root because that will throw exceptions) and use Directory.GetFiles on all of them. This will take some considerable time on an "average" disk, and will almost certainly throw access violation exceptions which you will have to handle.

A better approach is to either ask the user, or remember it in some way so you don't have to search for it.
There is no "find this file on this disk" method in .NET


First and foremost one should know what to google, Sorry we can't really teach how to google and there's no book available

Have a look into the below link, this might solve your problem.

http://stackoverflow.com/questions/1225294/c-sharp-find-a-file-within-all-possible-folders[^]


这篇关于如何在vb.net中获取文件名的路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆