关于文件路径的问题

haifeng39 2008-11-17 03:09:05
已知文件名,和此文件可能存在的四个路径,我想取得这个文件的正确路径。

比如一个图片image.jpg,它可能在c:\images下面,或d:\images下面。我想要的效果是点下button,在picturebox里显示这张图片。

请高手赐教!
...全文
76 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
haifeng39 2008-11-18
  • 打赏
  • 举报
回复
非常感谢!搞定了~
linmei_xiamiyisi 2008-11-18
  • 打赏
  • 举报
回复
qshzf 2008-11-18
  • 打赏
  • 举报
回复
try
{
可能的路径+文件名
}
ElaineZL 2008-11-18
  • 打赏
  • 举报
回复
Dim Boo_FileExist As Boolean
Boo_FileExist = IO.File.Exists("文件路径")
If Boo_FileExist = True Then
picturebox1.imagelocation=“文件路径”
End If
floadcloud 2008-11-17
  • 打赏
  • 举报
回复
先在硬盘中搜索图片,搜索完毕后将其加载到Picurebox中

以下为递归搜索文件系统代码

' <summary>
' Recurses the given path, adding all files on that path to
' the list box. After it finishes with the files, it
' calls itself once for each directory on the path.
' </summary>
' <param name="searchPath"></param>
Private Sub RecurseDirectory(searchPath As String)
' Split searchPath into a directory and a wildcard specification.
'
Dim directoryPath As String = Path.GetDirectoryName(searchPath)
Dim search As String = Path.GetFileName(searchPath)

' If a directory or search criteria are not specified, then return.
'
If directoryPath Is Nothing Or search Is Nothing Then
Return
End If

Dim files() As String

' File systems like NTFS that have
' access permissions might result in exceptions
' when looking into directories without permission.
' Catch those exceptions and return.
Try
files = Directory.GetFiles(directoryPath, search)
Catch e As UnauthorizedAccessException
Return
Catch e As DirectoryNotFoundException
Return
End Try

' Perform a BeginInvoke call to the list box
' in order to marshal to the correct thread. It is not
' very efficient to perform this marshal once for every
' file, so batch up multiple file calls into one
' marshal invocation.
Dim startingIndex As Integer = 0
While startingIndex < files.Length
' Batch up 20 files at once, unless at the
' end.
'
Dim count As Integer = 20
If count + startingIndex >= files.Length Then
count = files.Length - startingIndex
End If
' Begin the cross-thread call. Because you are passing
' immutable objects into this invoke method, you do not have to
' wait for it to finish. If these were complex objects, you would
' have to either create new instances of them or
' wait for the thread to process this invoke before modifying
' the objects.
Dim r As IAsyncResult = BeginInvoke(_fileListDelegate, New Object() {files, startingIndex, count})
startingIndex += count
End While
' Now that you have finished the files in this directory, recurse
' for each subdirectory.
Dim directories As String() = Directory.GetDirectories(directoryPath)
Dim d As String
For Each d In directories
RecurseDirectory(Path.Combine(d, search))
Next d
End Sub
groundsky 2008-11-17
  • 打赏
  • 举报
回复
io.File.Exists(文件路径)依次判断文件是否存在,如存在则载入

16,554

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧